node-datachannel
Advanced tools
Comparing version 0.5.5 to 0.6.0
@@ -5,3 +5,3 @@ cmake_minimum_required(VERSION 3.15) | ||
project(node_datachannel VERSION 0.5.5) | ||
project(node_datachannel VERSION 0.6.0) | ||
@@ -24,10 +24,4 @@ # -Dnapi_build_version=8 | ||
# Got linker error for arm64 | ||
# /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): relocation R_AARCH64_PREL64 against symbol `OPENSSL_armcap_P' which may bind externally can not be used when making a shared object; recompile with -fPIC | ||
# ../sysroot/usr/lib/aarch64-linux-gnu/libcrypto.a(sha1-armv8.o): in function `sha1_block_armv8': | ||
# (.text+0x1240): dangerous relocation: unsupported relocation | ||
if(NOT ${NODE_ARCH} STREQUAL "arm64") | ||
set(OPENSSL_USE_STATIC_LIBS TRUE) | ||
find_package(OpenSSL REQUIRED) | ||
endif() | ||
set(OPENSSL_USE_STATIC_LIBS TRUE) | ||
find_package(OpenSSL REQUIRED) | ||
@@ -44,3 +38,3 @@ include(FetchContent) | ||
option(NO_MEDIA "Disable media transport support in libdatachannel" OFF) | ||
option(NO_WEBSOCKET "Disable WebSocket support in libdatachannel" ON) | ||
option(NO_WEBSOCKET "Disable WebSocket support in libdatachannel" OFF) | ||
@@ -64,2 +58,4 @@ FetchContent_GetProperties(libdatachannel) | ||
src/thread-safe-callback.cpp | ||
src/web-socket-wrapper.cpp | ||
src/web-socket-server-wrapper.cpp | ||
src/main.cpp | ||
@@ -66,0 +62,0 @@ ${CMAKE_JS_SRC} |
@@ -23,1 +23,13 @@ # media Example | ||
``` | ||
For saving the stream to a file, use the following pipeline (mp4): | ||
``` | ||
gst-launch-1.0 -e udpsrc address=127.0.0.1 port=5000 caps="application/x-rtp" ! queue ! rtph264depay ! h264parse ! mp4mux ! filesink location=out.mp4 | ||
``` | ||
## Requirements | ||
- GStreamer 1.0 | ||
- gstreamer1.0-libav (sudo apt-get install gstreamer1.0-libav) | ||
- h264enc (sudo apt-get install h264enc) |
@@ -192,7 +192,23 @@ import * as stream from 'stream'; | ||
export class DataChannel { | ||
export interface Channel { | ||
close(): void; | ||
sendMessage(msg: string): boolean; | ||
sendMessageBinary(buffer: Uint8Array): boolean; | ||
isOpen(): boolean; | ||
bufferedAmount(): number; | ||
maxMessageSize(): number; | ||
setBufferedAmountLowThreshold(newSize: number): void; | ||
onOpen(cb: () => void): void; | ||
onClosed(cb: () => void): void; | ||
onError(cb: (err: string) => void): void; | ||
onBufferedAmountLow(cb: () => void): void; | ||
onMessage(cb: (msg: string | Buffer) => void): void; | ||
} | ||
export class DataChannel implements Channel { | ||
getLabel(): string; | ||
getId(): number; | ||
getProtocol(): string; | ||
// Channel implementation | ||
close(): void; | ||
sendMessage(msg: string): boolean; | ||
@@ -211,2 +227,51 @@ sendMessageBinary(buffer: Uint8Array): boolean; | ||
export interface WebSocketConfiguration { | ||
disableTlsVerification?: boolean; // default = false, if true, don't verify the TLS certificate | ||
proxyServer?: ProxyServer; // only non-authenticated http supported for now | ||
protocols?: string[]; | ||
connectionTimeout?: number; // miliseconds, zero to disable | ||
pingInterval?: number; // millisecondrs, zero to disable | ||
maxOutstandingPings?: number; | ||
caCertificatePemFile?: string; | ||
certificatePemFile?: string; | ||
keyPemFile?: string; | ||
keyPemPass?: string; | ||
maxMessageSize: number; | ||
} | ||
export class WebSocket implements Channel { | ||
constructor(config?: WebSocketConfiguration); | ||
// Channel implementation | ||
close(): void; | ||
sendMessage(msg: string): boolean; | ||
sendMessageBinary(buffer: Uint8Array): boolean; | ||
isOpen(): boolean; | ||
bufferedAmount(): number; | ||
maxMessageSize(): number; | ||
setBufferedAmountLowThreshold(newSize: number): void; | ||
onOpen(cb: () => void): void; | ||
onClosed(cb: () => void): void; | ||
onError(cb: (err: string) => void): void; | ||
onBufferedAmountLow(cb: () => void): void; | ||
onMessage(cb: (msg: string | Buffer) => void): void; | ||
} | ||
export interface WebSocketServerConfiguration { | ||
port?: number; // default 8080 | ||
enableTls?: boolean; // default = false; | ||
certificatePemFile?: string; | ||
keyPemFile?: string; | ||
keyPemPass?: string; | ||
bindAddress?: string; | ||
connectionTimeout?: number; // milliseconds | ||
maxMessageSize?: number; | ||
} | ||
export class WebSocketServer { | ||
constructor(config?: WebSocketServerConfiguration); | ||
port(): number; | ||
stop(): void; | ||
onClient(cb: (ws: WebSocket) => void): void; | ||
} | ||
export class PeerConnection { | ||
@@ -213,0 +278,0 @@ constructor(peerName: string, config: RtcConfig); |
@@ -19,2 +19,4 @@ // createRequire is native in node version >= 12 | ||
PeerConnection, | ||
WebSocket, | ||
WebSocketServer, | ||
} = nodeDataChannel; | ||
@@ -33,2 +35,4 @@ | ||
PeerConnection, | ||
WebSocket, | ||
WebSocketServer, | ||
// Extra exports | ||
@@ -35,0 +39,0 @@ DataChannelStream, |
{ | ||
"name": "node-datachannel", | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"description": "libdatachannel node bindings", | ||
@@ -47,3 +47,4 @@ "type": "module", | ||
"datachannel", | ||
"data channel" | ||
"data channel", | ||
"websocket" | ||
], | ||
@@ -50,0 +51,0 @@ "contributors": [ |
@@ -182,2 +182,69 @@ import { jest } from '@jest/globals'; | ||
describe('Websocket', () => { | ||
const webSocketServer = new nodeDataChannel.WebSocketServer({ bindAddress: '127.0.0.1', port: 1987 }); | ||
const clientSocket = new nodeDataChannel.WebSocket(); | ||
// Mocks | ||
const clientOnOpenMock = jest.fn(); | ||
const clientOnMessageMock = jest.fn(); | ||
const clientOnCLosedMock = jest.fn(); | ||
const webServerOnClientMock = jest.fn(); | ||
const webServerOnOpenMock = jest.fn(); | ||
const webServerOnMessageMock = jest.fn(); | ||
const webServerOnClosedMock = jest.fn(); | ||
webSocketServer.onClient((serverSocket) => { | ||
webServerOnClientMock(); | ||
serverSocket.onOpen(() => { | ||
webServerOnOpenMock(); | ||
}); | ||
serverSocket.onMessage((message) => { | ||
webServerOnMessageMock(message); | ||
serverSocket.sendMessage('reply to ' + message); | ||
serverSocket.close(); | ||
}); | ||
serverSocket.onClosed(() => { | ||
webServerOnClosedMock(); | ||
serverSocket.close(); | ||
}); | ||
}); | ||
test('can create a websocket client and connect to a server', (done) => { | ||
clientSocket.open('ws://127.0.0.1:1987'); | ||
clientSocket.onOpen(() => { | ||
clientOnOpenMock(); | ||
clientSocket.sendMessage('Hello'); | ||
}); | ||
clientSocket.onMessage((message) => { | ||
clientOnMessageMock(message); | ||
}); | ||
clientSocket.onClosed(() => { | ||
clientOnCLosedMock(); | ||
}); | ||
setTimeout(() => { | ||
expect(clientOnMessageMock.mock.calls[0][0]).toEqual('reply to Hello'); | ||
expect(clientOnOpenMock.mock.calls.length).toBe(1); | ||
expect(clientOnMessageMock.mock.calls.length).toBe(1); | ||
expect(clientOnCLosedMock.mock.calls.length).toBe(1); | ||
expect(webServerOnMessageMock.mock.calls[0][0]).toEqual('Hello'); | ||
expect(webServerOnOpenMock.mock.calls.length).toBe(1); | ||
expect(webServerOnMessageMock.mock.calls.length).toBe(1); | ||
expect(webServerOnClosedMock.mock.calls.length).toBe(0); | ||
clientSocket.close(); | ||
webSocketServer.stop(); | ||
done(); | ||
}, 3000); | ||
}); | ||
}); | ||
afterAll(() => { | ||
@@ -184,0 +251,0 @@ // Properly cleanup so Jest does not complain about asynchronous operations that weren't stopped. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1026806
98
19052