node-datachannel 0.12.0 → 0.20.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +5 -1
- package/.eslintrc.json +27 -0
- package/.prettierrc +12 -0
- package/CMakeLists.txt +13 -13
- package/dist/cjs/index.cjs +11 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/lib/datachannel-stream.cjs +101 -0
- package/dist/cjs/lib/datachannel-stream.cjs.map +1 -0
- package/dist/cjs/lib/index.cjs +61 -0
- package/dist/cjs/lib/index.cjs.map +1 -0
- package/dist/cjs/lib/node-datachannel.cjs +14 -0
- package/dist/cjs/lib/node-datachannel.cjs.map +1 -0
- package/dist/cjs/lib/websocket-server.cjs +44 -0
- package/dist/cjs/lib/websocket-server.cjs.map +1 -0
- package/dist/cjs/lib/websocket.cjs +8 -0
- package/dist/cjs/lib/websocket.cjs.map +1 -0
- package/dist/cjs/polyfill/Events.cjs +37 -0
- package/dist/cjs/polyfill/Events.cjs.map +1 -0
- package/dist/cjs/polyfill/Exception.cjs +34 -0
- package/dist/cjs/polyfill/Exception.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCCertificate.cjs +31 -0
- package/dist/cjs/polyfill/RTCCertificate.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCDataChannel.cjs +179 -0
- package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs +52 -0
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCError.cjs +76 -0
- package/dist/cjs/polyfill/RTCError.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCIceCandidate.cjs +129 -0
- package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCIceTransport.cjs +84 -0
- package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCPeerConnection.cjs +417 -0
- package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCSctpTransport.cjs +61 -0
- package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -0
- package/dist/cjs/polyfill/RTCSessionDescription.cjs +37 -0
- package/dist/cjs/polyfill/RTCSessionDescription.cjs.map +1 -0
- package/dist/cjs/polyfill/index.cjs +42 -0
- package/dist/cjs/polyfill/index.cjs.map +1 -0
- package/dist/esm/index.mjs +8 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/lib/datachannel-stream.mjs +78 -0
- package/dist/esm/lib/datachannel-stream.mjs.map +1 -0
- package/dist/esm/lib/index.mjs +44 -0
- package/dist/esm/lib/index.mjs.map +1 -0
- package/dist/esm/lib/node-datachannel.mjs +18 -0
- package/dist/esm/lib/node-datachannel.mjs.map +1 -0
- package/dist/esm/lib/websocket-server.mjs +42 -0
- package/dist/esm/lib/websocket-server.mjs.map +1 -0
- package/dist/esm/lib/websocket.mjs +6 -0
- package/dist/esm/lib/websocket.mjs.map +1 -0
- package/dist/esm/polyfill/Events.mjs +34 -0
- package/dist/esm/polyfill/Events.mjs.map +1 -0
- package/dist/esm/polyfill/Exception.mjs +28 -0
- package/dist/esm/polyfill/Exception.mjs.map +1 -0
- package/dist/esm/polyfill/RTCCertificate.mjs +27 -0
- package/dist/esm/polyfill/RTCCertificate.mjs.map +1 -0
- package/dist/esm/polyfill/RTCDataChannel.mjs +175 -0
- package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -0
- package/dist/esm/polyfill/RTCDtlsTransport.mjs +48 -0
- package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -0
- package/dist/esm/polyfill/RTCError.mjs +72 -0
- package/dist/esm/polyfill/RTCError.mjs.map +1 -0
- package/dist/esm/polyfill/RTCIceCandidate.mjs +125 -0
- package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -0
- package/dist/esm/polyfill/RTCIceTransport.mjs +80 -0
- package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -0
- package/dist/esm/polyfill/RTCPeerConnection.mjs +413 -0
- package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -0
- package/dist/esm/polyfill/RTCSctpTransport.mjs +57 -0
- package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -0
- package/dist/esm/polyfill/RTCSessionDescription.mjs +33 -0
- package/dist/esm/polyfill/RTCSessionDescription.mjs.map +1 -0
- package/dist/esm/polyfill/index.mjs +27 -0
- package/dist/esm/polyfill/index.mjs.map +1 -0
- package/dist/types/lib/datachannel-stream.d.ts +24 -0
- package/dist/types/lib/index.d.ts +164 -0
- package/dist/types/lib/types.d.ts +106 -0
- package/dist/types/lib/websocket-server.d.ts +13 -0
- package/dist/types/lib/websocket.d.ts +25 -0
- package/dist/types/polyfill/Events.d.ts +15 -0
- package/dist/types/polyfill/RTCCertificate.d.ts +8 -0
- package/dist/types/polyfill/RTCDataChannel.d.ts +29 -0
- package/dist/types/polyfill/RTCDtlsTransport.d.ts +17 -0
- package/dist/types/polyfill/RTCError.d.ts +16 -0
- package/dist/types/polyfill/RTCIceCandidate.d.ts +21 -0
- package/dist/types/polyfill/RTCIceTransport.d.ts +24 -0
- package/dist/types/polyfill/RTCPeerConnection.d.ts +56 -0
- package/dist/types/polyfill/RTCSctpTransport.d.ts +17 -0
- package/dist/types/polyfill/RTCSessionDescription.d.ts +9 -0
- package/{polyfill → dist/types/polyfill}/index.d.ts +3 -14
- package/jest.config.ts +14 -0
- package/package.json +47 -43
- package/rollup.config.mjs +63 -0
- package/src/index.ts +10 -0
- package/{lib/datachannel-stream.js → src/lib/datachannel-stream.ts} +16 -11
- package/src/lib/index.ts +180 -0
- package/src/lib/node-datachannel.ts +13 -0
- package/src/lib/types.ts +126 -0
- package/{lib/websocket-server.js → src/lib/websocket-server.ts} +10 -8
- package/src/lib/websocket.ts +26 -0
- package/src/polyfill/Events.ts +33 -0
- package/src/polyfill/Exception.ts +37 -0
- package/src/polyfill/RTCCertificate.ts +17 -0
- package/{polyfill/RTCDataChannel.js → src/polyfill/RTCDataChannel.ts} +43 -40
- package/src/polyfill/RTCDtlsTransport.ts +47 -0
- package/src/polyfill/RTCError.ts +71 -0
- package/{polyfill/RTCIceCandidate.js → src/polyfill/RTCIceCandidate.ts} +35 -35
- package/{polyfill/RTCIceTransport.js → src/polyfill/RTCIceTransport.ts} +22 -20
- package/{polyfill/RTCPeerConnection.js → src/polyfill/RTCPeerConnection.ts} +128 -114
- package/{polyfill/RTCSctpTransport.js → src/polyfill/RTCSctpTransport.ts} +16 -14
- package/{polyfill/RTCSessionDescription.js → src/polyfill/RTCSessionDescription.ts} +7 -12
- package/{polyfill/index.js → src/polyfill/index.ts} +10 -10
- package/tsconfig.json +20 -13
- package/.eslintrc.cjs +0 -8
- package/.github/FUNDING.yml +0 -2
- package/.github/workflows/build-linux.yml +0 -109
- package/.github/workflows/build-mac-m1.yml +0 -38
- package/.github/workflows/build-mac-x64.yml +0 -40
- package/.github/workflows/build-win.yml +0 -74
- package/.github/workflows/lint.yml +0 -20
- package/.github/workflows/npm-publish-manual.yml +0 -23
- package/.prettierrc.cjs +0 -8
- package/build-containers/Dockerfile.alpine +0 -6
- package/build-containers/Dockerfile.debian +0 -7
- package/cmake/toolchain/ci.cmake +0 -23
- package/examples/client-server/README.md +0 -22
- package/examples/client-server/client-benchmark.js +0 -230
- package/examples/client-server/client-periodic.js +0 -189
- package/examples/client-server/client.js +0 -111
- package/examples/client-server/package-lock.json +0 -289
- package/examples/client-server/package.json +0 -16
- package/examples/client-server/signaling-server.js +0 -39
- package/examples/electron-demo/README.md +0 -58
- package/examples/electron-demo/forge.config.js +0 -49
- package/examples/electron-demo/package-lock.json +0 -15877
- package/examples/electron-demo/package.json +0 -44
- package/examples/electron-demo/src/index.css +0 -7
- package/examples/electron-demo/src/index.html +0 -29
- package/examples/electron-demo/src/main.js +0 -53
- package/examples/electron-demo/src/node-datachannel.js +0 -123
- package/examples/electron-demo/src/preload.js +0 -28
- package/examples/electron-demo/src/renderer.js +0 -58
- package/examples/electron-demo/webpack.main.config.js +0 -21
- package/examples/electron-demo/webpack.renderer.config.js +0 -13
- package/examples/electron-demo/webpack.rules.js +0 -35
- package/examples/media/README.md +0 -34
- package/examples/media/main.html +0 -45
- package/examples/media/media.js +0 -54
- package/examples/simple-peer-usage/main.js +0 -28
- package/examples/simple-peer-usage/package-lock.json +0 -317
- package/examples/simple-peer-usage/package.json +0 -16
- package/examples/websocket/websocket-client.js +0 -20
- package/examples/websocket/websocket-server.js +0 -22
- package/jest.config.cjs +0 -7
- package/lib/index.cjs +0 -194
- package/lib/index.d.cts +0 -300
- package/lib/index.d.ts +0 -300
- package/lib/index.js +0 -58
- package/lib/node-datachannel.js +0 -7
- package/polyfill/Events.d.ts +0 -9
- package/polyfill/Events.js +0 -29
- package/polyfill/Exception.js +0 -23
- package/polyfill/RTCCertificate.d.ts +0 -7
- package/polyfill/RTCCertificate.js +0 -17
- package/polyfill/RTCDataChannel.d.ts +0 -35
- package/polyfill/RTCDtlsTransport.d.ts +0 -10
- package/polyfill/RTCDtlsTransport.js +0 -47
- package/polyfill/RTCError.d.ts +0 -11
- package/polyfill/RTCError.js +0 -65
- package/polyfill/RTCIceCandidate.d.ts +0 -20
- package/polyfill/RTCIceTransport.d.ts +0 -18
- package/polyfill/RTCPeerConnection.d.ts +0 -62
- package/polyfill/RTCSctpTransport.d.ts +0 -10
- package/polyfill/RTCSessionDescription.d.ts +0 -8
- package/polyfill/index.cjs +0 -1333
- package/polyfill/index.d.cts +0 -37
- package/test/connectivity.js +0 -86
- package/test/jest-tests/basic.test.js +0 -37
- package/test/jest-tests/multiple-run.test.js +0 -73
- package/test/jest-tests/p2p.test.js +0 -99
- package/test/jest-tests/polyfill.test.js +0 -10
- package/test/jest-tests/streams.test.js +0 -48
- package/test/jest-tests/websocket.test.js +0 -69
- package/test/polyfill-connectivity.js +0 -89
- package/test/websockets.js +0 -50
- package/test/wpt-tests/README.md +0 -46
- package/test/wpt-tests/chrome-failed-tests.js +0 -42
- package/test/wpt-tests/index.js +0 -96
- package/test/wpt-tests/last-test-results.md +0 -301
- package/test/wpt-tests/package-lock.json +0 -1712
- package/test/wpt-tests/package.json +0 -19
- package/test/wpt-tests/wpt-test-list.js +0 -139
- package/test/wpt-tests/wpt.js +0 -131
- /package/src/{data-channel-wrapper.cpp → cpp/data-channel-wrapper.cpp} +0 -0
- /package/src/{data-channel-wrapper.h → cpp/data-channel-wrapper.h} +0 -0
- /package/src/{main.cpp → cpp/main.cpp} +0 -0
- /package/src/{media-audio-wrapper.cpp → cpp/media-audio-wrapper.cpp} +0 -0
- /package/src/{media-audio-wrapper.h → cpp/media-audio-wrapper.h} +0 -0
- /package/src/{media-direction.cpp → cpp/media-direction.cpp} +0 -0
- /package/src/{media-direction.h → cpp/media-direction.h} +0 -0
- /package/src/{media-rtcpreceivingsession-wrapper.cpp → cpp/media-rtcpreceivingsession-wrapper.cpp} +0 -0
- /package/src/{media-rtcpreceivingsession-wrapper.h → cpp/media-rtcpreceivingsession-wrapper.h} +0 -0
- /package/src/{media-track-wrapper.cpp → cpp/media-track-wrapper.cpp} +0 -0
- /package/src/{media-track-wrapper.h → cpp/media-track-wrapper.h} +0 -0
- /package/src/{media-video-wrapper.cpp → cpp/media-video-wrapper.cpp} +0 -0
- /package/src/{media-video-wrapper.h → cpp/media-video-wrapper.h} +0 -0
- /package/src/{peer-connection-wrapper.cpp → cpp/peer-connection-wrapper.cpp} +0 -0
- /package/src/{peer-connection-wrapper.h → cpp/peer-connection-wrapper.h} +0 -0
- /package/src/{rtc-wrapper.cpp → cpp/rtc-wrapper.cpp} +0 -0
- /package/src/{rtc-wrapper.h → cpp/rtc-wrapper.h} +0 -0
- /package/src/{thread-safe-callback.cpp → cpp/thread-safe-callback.cpp} +0 -0
- /package/src/{thread-safe-callback.h → cpp/thread-safe-callback.h} +0 -0
- /package/src/{web-socket-server-wrapper.cpp → cpp/web-socket-server-wrapper.cpp} +0 -0
- /package/src/{web-socket-server-wrapper.h → cpp/web-socket-server-wrapper.h} +0 -0
- /package/src/{web-socket-wrapper.cpp → cpp/web-socket-wrapper.cpp} +0 -0
- /package/src/{web-socket-wrapper.h → cpp/web-socket-wrapper.h} +0 -0
- /package/{polyfill → src/polyfill}/README.md +0 -0
package/package.json
CHANGED
|
@@ -1,52 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-datachannel",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "libdatachannel node bindings",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.20.0-alpha.2",
|
|
4
|
+
"description": "WebRTC For Node.js and Electron. libdatachannel node bindings.",
|
|
5
|
+
"main": "./dist/cjs/lib/index.cjs",
|
|
6
|
+
"module": "./dist/esm/lib/index.mjs",
|
|
7
|
+
"types": "./dist/types/lib/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"require": {
|
|
14
|
-
"types": "./lib/index.d.cts",
|
|
15
|
-
"default": "./lib/index.cjs"
|
|
16
|
-
}
|
|
10
|
+
"types": "./dist/types/lib/index.d.ts",
|
|
11
|
+
"require": "./dist/cjs/lib/index.cjs",
|
|
12
|
+
"import": "./dist/esm/lib/index.mjs",
|
|
13
|
+
"default": "./dist/lib/esm/index.mjs"
|
|
17
14
|
},
|
|
18
15
|
"./polyfill": {
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"require": {
|
|
24
|
-
"types": "./polyfill/index.d.cts",
|
|
25
|
-
"default": "./polyfill/index.cjs"
|
|
26
|
-
}
|
|
16
|
+
"types": "./dist/types/polyfill/index.d.ts",
|
|
17
|
+
"require": "./dist/cjs/polyfill/index.cjs",
|
|
18
|
+
"import": "./dist/esm/polyfill/index.mjs",
|
|
19
|
+
"default": "./dist/polyfill/esm/index.mjs"
|
|
27
20
|
}
|
|
28
21
|
},
|
|
29
22
|
"engines": {
|
|
30
23
|
"node": ">=16.0.0"
|
|
31
24
|
},
|
|
32
|
-
"directories": {
|
|
33
|
-
"lib": "lib",
|
|
34
|
-
"test": "test"
|
|
35
|
-
},
|
|
36
|
-
"_from": "node-datachannel@latest",
|
|
37
25
|
"scripts": {
|
|
38
26
|
"install": "prebuild-install -r napi || (npm install --ignore-scripts --production=false && npm run _prebuild)",
|
|
39
|
-
"install
|
|
40
|
-
"install
|
|
41
|
-
"build": "
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
27
|
+
"install:nice": "npm run clean && npm install --ignore-scripts --production=false && cmake-js build --CDUSE_NICE=1",
|
|
28
|
+
"install:gnu": "npm run clean && npm install --ignore-scripts --production=false && cmake-js build --CDUSE_GNUTLS=1",
|
|
29
|
+
"build": "npm run compile && npm run build:tsc",
|
|
30
|
+
"compile": "cmake-js build",
|
|
31
|
+
"compile:debug": "cmake-js build -D",
|
|
32
|
+
"build:tsc": "rimraf dist && rollup -c",
|
|
33
|
+
"build:tsc:watch": "rollup -c -w",
|
|
34
|
+
"clean": "rimraf dist build",
|
|
35
|
+
"lint": "eslint . --ext .ts --ext .mts",
|
|
46
36
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
47
|
-
"
|
|
48
|
-
"test
|
|
49
|
-
"
|
|
37
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
38
|
+
"test:wpt": "npm run run:wpt:server & (sleep 8 && (npm run run:wpt:test | tee test/wpt-tests/last-test-results.md) )",
|
|
39
|
+
"run:wpt:server": "cd test/wpt-tests/wpt && ./wpt serve",
|
|
40
|
+
"run:wpt:test": "ts-node test/wpt-tests/index.ts",
|
|
41
|
+
"_prebuild": "prebuild -r napi --backend cmake-js",
|
|
42
|
+
"prepack": "npm run build:tsc"
|
|
50
43
|
},
|
|
51
44
|
"binary": {
|
|
52
45
|
"napi_versions": [
|
|
@@ -82,19 +75,30 @@
|
|
|
82
75
|
},
|
|
83
76
|
"homepage": "https://github.com/murat-dogan/node-datachannel#readme",
|
|
84
77
|
"devDependencies": {
|
|
78
|
+
"@rollup/plugin-esm-shim": "^0.1.7",
|
|
79
|
+
"@types/jest": "^29.5.12",
|
|
85
80
|
"@types/node": "^20.6.1",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
87
|
-
"@typescript-eslint/parser": "^
|
|
81
|
+
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
82
|
+
"@typescript-eslint/parser": "^7.17.0",
|
|
88
83
|
"cmake-js": "^6.3.2",
|
|
89
|
-
"eslint": "^8.
|
|
90
|
-
"eslint-config-prettier": "^
|
|
91
|
-
"eslint-plugin-
|
|
84
|
+
"eslint": "^8.57.0",
|
|
85
|
+
"eslint-config-prettier": "^9.1.0",
|
|
86
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
87
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
92
88
|
"jest": "^29.7.0",
|
|
89
|
+
"jsdom": "^24.1.1",
|
|
93
90
|
"node-addon-api": "^7.0.0",
|
|
94
91
|
"prebuild": "^12.0.0",
|
|
95
|
-
"prettier": "^
|
|
96
|
-
"
|
|
97
|
-
"
|
|
92
|
+
"prettier": "^3.3.3",
|
|
93
|
+
"puppeteer": "^22.14.0",
|
|
94
|
+
"rimraf": "^5.0.9",
|
|
95
|
+
"rollup": "^4.22.5",
|
|
96
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
97
|
+
"rollup-plugin-esbuild": "^6.1.1",
|
|
98
|
+
"ts-api-utils": "^1.3.0",
|
|
99
|
+
"ts-jest": "^29.2.3",
|
|
100
|
+
"ts-node": "^10.9.2",
|
|
101
|
+
"typescript": "5.4"
|
|
98
102
|
},
|
|
99
103
|
"dependencies": {
|
|
100
104
|
"node-domexception": "^2.0.1",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import dts from 'rollup-plugin-dts';
|
|
2
|
+
import esbuild from 'rollup-plugin-esbuild';
|
|
3
|
+
import esmShim from '@rollup/plugin-esm-shim';
|
|
4
|
+
|
|
5
|
+
const external = (id) => {
|
|
6
|
+
return !/^[./]/.test(id);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const bundle = (config) => ({
|
|
10
|
+
...config,
|
|
11
|
+
input: 'src/index.ts',
|
|
12
|
+
external,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default [
|
|
16
|
+
bundle({
|
|
17
|
+
plugins: [esmShim(), esbuild()],
|
|
18
|
+
output: [
|
|
19
|
+
{
|
|
20
|
+
dir: 'dist/esm',
|
|
21
|
+
format: 'es',
|
|
22
|
+
exports: 'named',
|
|
23
|
+
sourcemap: true,
|
|
24
|
+
entryFileNames: '[name].mjs',
|
|
25
|
+
preserveModules: true, // Keep directory structure and files
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
dir: 'dist/cjs',
|
|
29
|
+
format: 'cjs',
|
|
30
|
+
exports: 'named',
|
|
31
|
+
sourcemap: true,
|
|
32
|
+
entryFileNames: '[name].cjs',
|
|
33
|
+
preserveModules: true, // Keep directory structure and files
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
}),
|
|
37
|
+
// types
|
|
38
|
+
{
|
|
39
|
+
plugins: [dts()],
|
|
40
|
+
input: 'src/lib/index.ts',
|
|
41
|
+
external,
|
|
42
|
+
output: {
|
|
43
|
+
dir: 'dist/types/lib',
|
|
44
|
+
format: 'cjs',
|
|
45
|
+
exports: 'named',
|
|
46
|
+
preserveModules: true, // Keep directory structure and files
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
plugins: [dts()],
|
|
51
|
+
input: 'src/polyfill/index.ts',
|
|
52
|
+
external: (id) => {
|
|
53
|
+
if (id.startsWith('../lib')) return true;
|
|
54
|
+
return !/^[./]/.test(id);
|
|
55
|
+
},
|
|
56
|
+
output: {
|
|
57
|
+
dir: 'dist/types/polyfill',
|
|
58
|
+
format: 'cjs',
|
|
59
|
+
exports: 'named',
|
|
60
|
+
preserveModules: true, // Keep directory structure and files
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
];
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// This file is created for builder process
|
|
2
|
+
// So builder can find and compile all files and folders
|
|
3
|
+
// Not intended to be imported directly
|
|
4
|
+
|
|
5
|
+
import n from './lib/index';
|
|
6
|
+
import p from './polyfill/index';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export const nodeDataChannel = n;
|
|
10
|
+
export const polyfill = p;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import stream from 'stream';
|
|
1
|
+
import * as stream from 'stream';
|
|
2
|
+
// import { DataChannel } from './node-datachannel.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Turns a node-datachannel DataChannel into a real Node.js stream, complete with buffering,
|
|
@@ -9,7 +10,11 @@ import stream from 'stream';
|
|
|
9
10
|
* the protocol level, and is preserved here throughout.
|
|
10
11
|
*/
|
|
11
12
|
export default class DataChannelStream extends stream.Duplex {
|
|
12
|
-
|
|
13
|
+
private _rawChannel: any;
|
|
14
|
+
private _readActive: boolean;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
constructor(rawChannel: any, streamOptions?: Omit<stream.DuplexOptions, 'objectMode'>) {
|
|
13
18
|
super({
|
|
14
19
|
allowHalfOpen: false, // Default to autoclose on end().
|
|
15
20
|
...streamOptions,
|
|
@@ -19,7 +24,7 @@ export default class DataChannelStream extends stream.Duplex {
|
|
|
19
24
|
this._rawChannel = rawChannel;
|
|
20
25
|
this._readActive = true;
|
|
21
26
|
|
|
22
|
-
rawChannel.onMessage((msg) => {
|
|
27
|
+
rawChannel.onMessage((msg: any) => {
|
|
23
28
|
if (!this._readActive) return; // If the buffer is full, drop messages.
|
|
24
29
|
|
|
25
30
|
// If the push is rejected, we pause reading until the next call to _read().
|
|
@@ -32,7 +37,7 @@ export default class DataChannelStream extends stream.Duplex {
|
|
|
32
37
|
this.destroy();
|
|
33
38
|
});
|
|
34
39
|
|
|
35
|
-
rawChannel.onError((errMsg) => {
|
|
40
|
+
rawChannel.onError((errMsg: string) => {
|
|
36
41
|
this.destroy(new Error(`DataChannel error: ${errMsg}`));
|
|
37
42
|
});
|
|
38
43
|
|
|
@@ -43,12 +48,12 @@ export default class DataChannelStream extends stream.Duplex {
|
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
_read() {
|
|
51
|
+
_read(): void {
|
|
47
52
|
// Stop dropping messages, if the buffer filling up meant we were doing so before.
|
|
48
53
|
this._readActive = true;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
_write(chunk,
|
|
56
|
+
_write(chunk, _encoding, callback): void {
|
|
52
57
|
let sentOk;
|
|
53
58
|
|
|
54
59
|
try {
|
|
@@ -71,26 +76,26 @@ export default class DataChannelStream extends stream.Duplex {
|
|
|
71
76
|
}
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
_final(callback) {
|
|
79
|
+
_final(callback): void {
|
|
75
80
|
if (!this.allowHalfOpen) this.destroy();
|
|
76
81
|
callback(null);
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
_destroy(maybeErr, callback) {
|
|
84
|
+
_destroy(maybeErr, callback): void {
|
|
80
85
|
// When the stream is destroyed, we close the DataChannel.
|
|
81
86
|
this._rawChannel.close();
|
|
82
87
|
callback(maybeErr);
|
|
83
88
|
}
|
|
84
89
|
|
|
85
|
-
get label() {
|
|
90
|
+
get label(): string {
|
|
86
91
|
return this._rawChannel.getLabel();
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
get id() {
|
|
94
|
+
get id(): number {
|
|
90
95
|
return this._rawChannel.getId();
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
get protocol() {
|
|
98
|
+
get protocol(): string {
|
|
94
99
|
return this._rawChannel.getProtocol();
|
|
95
100
|
}
|
|
96
101
|
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import nodeDataChannel from './node-datachannel';
|
|
2
|
+
import _DataChannelStream from './datachannel-stream';
|
|
3
|
+
import { WebSocketServer } from './websocket-server';
|
|
4
|
+
import { Channel, DataChannelInitConfig, DescriptionType, Direction, LogLevel, RtcConfig, RTCIceConnectionState, RTCIceGatheringState, RTCPeerConnectionState, RTCSdpType, RTCSignalingState, SctpSettings, SelectedCandidateInfo } from './types';
|
|
5
|
+
import { WebSocket } from './websocket';
|
|
6
|
+
|
|
7
|
+
export function preload(): void { nodeDataChannel.preload(); }
|
|
8
|
+
export function initLogger(level: LogLevel): void { nodeDataChannel.initLogger(level); }
|
|
9
|
+
export function cleanup(): void { nodeDataChannel.cleanup(); }
|
|
10
|
+
export function setSctpSettings(settings: SctpSettings): void { nodeDataChannel.setSctpSettings(settings); }
|
|
11
|
+
|
|
12
|
+
export interface Audio {
|
|
13
|
+
addAudioCodec(payloadType: number, codec: string, profile?: string): void;
|
|
14
|
+
addOpusCodec(payloadType: number, profile?: string): string;
|
|
15
|
+
direction(): Direction;
|
|
16
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
17
|
+
mid(): string;
|
|
18
|
+
setDirection(dir: Direction): void;
|
|
19
|
+
description(): string;
|
|
20
|
+
removeFormat(fmt: string): void;
|
|
21
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
22
|
+
removeSSRC(ssrc: number): void;
|
|
23
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
24
|
+
hasSSRC(ssrc: number): boolean;
|
|
25
|
+
getSSRCs(): number[];
|
|
26
|
+
getCNameForSsrc(ssrc: number): string;
|
|
27
|
+
setBitrate(bitRate: number): void;
|
|
28
|
+
getBitrate(): number;
|
|
29
|
+
hasPayloadType(payloadType: number): boolean;
|
|
30
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
31
|
+
addRTPMap(): void;
|
|
32
|
+
parseSdpLine(line: string): void;
|
|
33
|
+
}
|
|
34
|
+
export const Audio: {
|
|
35
|
+
new(mid: string, dir: Direction): Audio
|
|
36
|
+
} = nodeDataChannel.Audio
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
export interface Video {
|
|
40
|
+
addVideoCodec(payloadType: number, codec: string, profile?: string): void;
|
|
41
|
+
addH264Codec(payloadType: number, profile?: string): void;
|
|
42
|
+
addVP8Codec(payloadType: number): void;
|
|
43
|
+
addVP9Codec(payloadType: number): void;
|
|
44
|
+
direction(): Direction;
|
|
45
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
46
|
+
mid(): string;
|
|
47
|
+
setDirection(dir: Direction): void;
|
|
48
|
+
description(): string;
|
|
49
|
+
removeFormat(fmt: string): void;
|
|
50
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
51
|
+
removeSSRC(ssrc: number): void;
|
|
52
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
53
|
+
hasSSRC(ssrc: number): boolean;
|
|
54
|
+
getSSRCs(): number[];
|
|
55
|
+
getCNameForSsrc(ssrc: number): string;
|
|
56
|
+
setBitrate(bitRate: number): void;
|
|
57
|
+
getBitrate(): number;
|
|
58
|
+
hasPayloadType(payloadType: number): boolean;
|
|
59
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
60
|
+
addRTPMap(): void;
|
|
61
|
+
parseSdpLine(line: string): void;
|
|
62
|
+
}
|
|
63
|
+
export const Video: {
|
|
64
|
+
new(mid: string, dir: Direction): Video
|
|
65
|
+
} = nodeDataChannel.Video
|
|
66
|
+
|
|
67
|
+
export interface Track {
|
|
68
|
+
direction(): Direction;
|
|
69
|
+
mid(): string;
|
|
70
|
+
type(): string;
|
|
71
|
+
close(): void;
|
|
72
|
+
sendMessage(msg: string): boolean;
|
|
73
|
+
sendMessageBinary(buffer: Buffer): boolean;
|
|
74
|
+
isOpen(): boolean;
|
|
75
|
+
isClosed(): boolean;
|
|
76
|
+
bufferedAmount(): number;
|
|
77
|
+
maxMessageSize(): number;
|
|
78
|
+
requestBitrate(bitRate: number): boolean;
|
|
79
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
80
|
+
requestKeyframe(): boolean;
|
|
81
|
+
setMediaHandler(handler: RtcpReceivingSession): void;
|
|
82
|
+
onOpen(cb: () => void): void;
|
|
83
|
+
onClosed(cb: () => void): void;
|
|
84
|
+
onError(cb: (err: string) => void): void;
|
|
85
|
+
onMessage(cb: (msg: Buffer) => void): void;
|
|
86
|
+
}
|
|
87
|
+
export const Track: {
|
|
88
|
+
new(): Track
|
|
89
|
+
} = nodeDataChannel.Track
|
|
90
|
+
|
|
91
|
+
export interface DataChannel extends Channel {
|
|
92
|
+
getLabel(): string;
|
|
93
|
+
getId(): number;
|
|
94
|
+
getProtocol(): string;
|
|
95
|
+
|
|
96
|
+
// Channel implementation
|
|
97
|
+
close(): void;
|
|
98
|
+
sendMessage(msg: string): boolean;
|
|
99
|
+
sendMessageBinary(buffer: Uint8Array): boolean;
|
|
100
|
+
isOpen(): boolean;
|
|
101
|
+
bufferedAmount(): number;
|
|
102
|
+
maxMessageSize(): number;
|
|
103
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
104
|
+
onOpen(cb: () => void): void;
|
|
105
|
+
onClosed(cb: () => void): void;
|
|
106
|
+
onError(cb: (err: string) => void): void;
|
|
107
|
+
onBufferedAmountLow(cb: () => void): void;
|
|
108
|
+
onMessage(cb: (msg: string | Buffer) => void): void;
|
|
109
|
+
}
|
|
110
|
+
export const DataChannel: {
|
|
111
|
+
// DataChannel implementation
|
|
112
|
+
} = nodeDataChannel.DataChannel
|
|
113
|
+
|
|
114
|
+
export interface PeerConnection {
|
|
115
|
+
close(): void;
|
|
116
|
+
setLocalDescription(type?: DescriptionType): void;
|
|
117
|
+
setRemoteDescription(sdp: string, type: DescriptionType): void;
|
|
118
|
+
localDescription(): { type: DescriptionType; sdp: RTCSdpType } | null;
|
|
119
|
+
remoteDescription(): { type: DescriptionType; sdp: string } | null;
|
|
120
|
+
addRemoteCandidate(candidate: string, mid: string): void;
|
|
121
|
+
createDataChannel(label: string, config?: DataChannelInitConfig): DataChannel;
|
|
122
|
+
addTrack(media: Video | Audio): Track;
|
|
123
|
+
hasMedia(): boolean;
|
|
124
|
+
state(): RTCPeerConnectionState;
|
|
125
|
+
iceState(): RTCIceConnectionState;
|
|
126
|
+
signalingState(): RTCSignalingState;
|
|
127
|
+
gatheringState(): RTCIceGatheringState;
|
|
128
|
+
onLocalDescription(cb: (sdp: string, type: DescriptionType) => void): void;
|
|
129
|
+
onLocalCandidate(cb: (candidate: string, mid: string) => void): void;
|
|
130
|
+
onStateChange(cb: (state: string) => void): void;
|
|
131
|
+
onIceStateChange(cb: (state: string) => void): void;
|
|
132
|
+
onSignalingStateChange(cb: (state: string) => void): void;
|
|
133
|
+
onGatheringStateChange(cb: (state: string) => void): void;
|
|
134
|
+
onDataChannel(cb: (dc: DataChannel) => void): void;
|
|
135
|
+
onTrack(cb: (track: Track) => void): void;
|
|
136
|
+
bytesSent(): number;
|
|
137
|
+
bytesReceived(): number;
|
|
138
|
+
rtt(): number;
|
|
139
|
+
getSelectedCandidatePair(): { local: SelectedCandidateInfo; remote: SelectedCandidateInfo } | null;
|
|
140
|
+
maxDataChannelId(): number;
|
|
141
|
+
maxMessageSize(): number;
|
|
142
|
+
}
|
|
143
|
+
export const PeerConnection: {
|
|
144
|
+
new(peerName: string, config: RtcConfig): PeerConnection
|
|
145
|
+
} = nodeDataChannel.PeerConnection
|
|
146
|
+
|
|
147
|
+
export class RtcpReceivingSession {
|
|
148
|
+
//
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**export {
|
|
152
|
+
Channel, DataChannelInitConfig, DescriptionType,
|
|
153
|
+
Direction, LogLevel, RtcConfig, SctpSettings,
|
|
154
|
+
SelectedCandidateInfo, RTCIceConnectionState,
|
|
155
|
+
RTCIceGathererState, RTCIceGatheringState,
|
|
156
|
+
RTCIceTransportState, RTCPeerConnectionState,
|
|
157
|
+
RTCSdpType, RTCSignalingState, RelayType,
|
|
158
|
+
ProxyServerType, TransportPolicy,
|
|
159
|
+
WebSocketServerConfiguration, IceServer, ProxyServer
|
|
160
|
+
} from './types';**/
|
|
161
|
+
export { WebSocketServer } from './websocket-server';
|
|
162
|
+
export { WebSocket } from './websocket';
|
|
163
|
+
|
|
164
|
+
export const DataChannelStream = _DataChannelStream;
|
|
165
|
+
|
|
166
|
+
export default {
|
|
167
|
+
initLogger,
|
|
168
|
+
cleanup,
|
|
169
|
+
preload,
|
|
170
|
+
setSctpSettings,
|
|
171
|
+
RtcpReceivingSession,
|
|
172
|
+
Track,
|
|
173
|
+
Video,
|
|
174
|
+
Audio,
|
|
175
|
+
DataChannel,
|
|
176
|
+
PeerConnection,
|
|
177
|
+
WebSocket,
|
|
178
|
+
WebSocketServer,
|
|
179
|
+
DataChannelStream
|
|
180
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
let nodeDataChannel;
|
|
2
|
+
|
|
3
|
+
try {
|
|
4
|
+
// from dist
|
|
5
|
+
nodeDataChannel = require('../../../build/Release/node_datachannel.node');
|
|
6
|
+
}
|
|
7
|
+
catch (e) {
|
|
8
|
+
// from src
|
|
9
|
+
nodeDataChannel = require('../../build/Release/node_datachannel.node');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default nodeDataChannel;
|
|
13
|
+
|
package/src/lib/types.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export interface Channel {
|
|
2
|
+
close(): void;
|
|
3
|
+
sendMessage(msg: string): boolean;
|
|
4
|
+
sendMessageBinary(buffer: Uint8Array): boolean;
|
|
5
|
+
isOpen(): boolean;
|
|
6
|
+
bufferedAmount(): number;
|
|
7
|
+
maxMessageSize(): number;
|
|
8
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
9
|
+
onOpen(cb: () => void): void;
|
|
10
|
+
onClosed(cb: () => void): void;
|
|
11
|
+
onError(cb: (err: string) => void): void;
|
|
12
|
+
onBufferedAmountLow(cb: () => void): void;
|
|
13
|
+
onMessage(cb: (msg: string | Buffer) => void): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface WebSocketServerConfiguration {
|
|
17
|
+
port?: number; // default 8080
|
|
18
|
+
enableTls?: boolean; // default = false;
|
|
19
|
+
certificatePemFile?: string;
|
|
20
|
+
keyPemFile?: string;
|
|
21
|
+
keyPemPass?: string;
|
|
22
|
+
bindAddress?: string;
|
|
23
|
+
connectionTimeout?: number; // milliseconds
|
|
24
|
+
maxMessageSize?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Enum in d.ts is tricky
|
|
28
|
+
export type LogLevel = 'Verbose' | 'Debug' | 'Info' | 'Warning' | 'Error' | 'Fatal';
|
|
29
|
+
|
|
30
|
+
// SCTP Settings
|
|
31
|
+
export interface SctpSettings {
|
|
32
|
+
recvBufferSize?: number;
|
|
33
|
+
sendBufferSize?: number;
|
|
34
|
+
maxChunksOnQueue?: number;
|
|
35
|
+
initialCongestionWindow?: number;
|
|
36
|
+
congestionControlModule?: number;
|
|
37
|
+
delayedSackTime?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Proxy Server
|
|
41
|
+
export type ProxyServerType = 'Socks5' | 'Http';
|
|
42
|
+
export interface ProxyServer {
|
|
43
|
+
type: ProxyServerType;
|
|
44
|
+
ip: string;
|
|
45
|
+
port: number;
|
|
46
|
+
username?: string;
|
|
47
|
+
password?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const enum RelayType {
|
|
51
|
+
TurnUdp = 'TurnUdp',
|
|
52
|
+
TurnTcp = 'TurnTcp',
|
|
53
|
+
TurnTls = 'TurnTls',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface IceServer {
|
|
57
|
+
hostname: string;
|
|
58
|
+
port: number;
|
|
59
|
+
username?: string;
|
|
60
|
+
password?: string;
|
|
61
|
+
relayType?: RelayType;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type TransportPolicy = 'all' | 'relay';
|
|
65
|
+
|
|
66
|
+
export interface RtcConfig {
|
|
67
|
+
iceServers: (string | IceServer)[];
|
|
68
|
+
proxyServer?: ProxyServer;
|
|
69
|
+
bindAddress?: string;
|
|
70
|
+
enableIceTcp?: boolean;
|
|
71
|
+
enableIceUdpMux?: boolean;
|
|
72
|
+
disableAutoNegotiation?: boolean;
|
|
73
|
+
forceMediaTransport?: boolean;
|
|
74
|
+
portRangeBegin?: number;
|
|
75
|
+
portRangeEnd?: number;
|
|
76
|
+
maxMessageSize?: number;
|
|
77
|
+
mtu?: number;
|
|
78
|
+
iceTransportPolicy?: TransportPolicy;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Lowercase to match the description type string from libdatachannel
|
|
82
|
+
export enum DescriptionType {
|
|
83
|
+
Unspec = 'unspec',
|
|
84
|
+
Offer = 'offer',
|
|
85
|
+
Answer = 'answer',
|
|
86
|
+
Pranswer = 'pranswer',
|
|
87
|
+
Rollback = 'rollback',
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type RTCSdpType = 'answer' | 'offer' | 'pranswer' | 'rollback';
|
|
91
|
+
|
|
92
|
+
export type RTCIceTransportState = "checking" | "closed" | "completed" | "connected" | "disconnected" | "failed" | "new";
|
|
93
|
+
export type RTCPeerConnectionState = "closed" | "connected" | "connecting" | "disconnected" | "failed" | "new";
|
|
94
|
+
export type RTCIceConnectionState = "checking" | "closed" | "completed" | "connected" | "disconnected" | "failed" | "new";
|
|
95
|
+
export type RTCIceGathererState = "complete" | "gathering" | "new";
|
|
96
|
+
export type RTCIceGatheringState = "complete" | "gathering" | "new";
|
|
97
|
+
export type RTCSignalingState = "closed" | "have-local-offer" | "have-local-pranswer" | "have-remote-offer" | "have-remote-pranswer" | "stable";
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export interface DataChannelInitConfig {
|
|
101
|
+
protocol?: string;
|
|
102
|
+
negotiated?: boolean;
|
|
103
|
+
id?: number;
|
|
104
|
+
unordered?: boolean; // Reliability
|
|
105
|
+
maxPacketLifeTime?: number; // Reliability
|
|
106
|
+
maxRetransmits?: number; // Reliability
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface SelectedCandidateInfo {
|
|
110
|
+
address: string;
|
|
111
|
+
port: number;
|
|
112
|
+
type: string;
|
|
113
|
+
transportType: string;
|
|
114
|
+
candidate: string;
|
|
115
|
+
mid: string;
|
|
116
|
+
priority: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Must be same as rtc enum class Direction
|
|
120
|
+
export const enum Direction {
|
|
121
|
+
SendOnly = 'SendOnly',
|
|
122
|
+
RecvOnly = 'RecvOnly',
|
|
123
|
+
SendRecv = 'SendRecv',
|
|
124
|
+
Inactive = 'Inactive',
|
|
125
|
+
Unknown = 'Unknown',
|
|
126
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import nodeDataChannel from './node-datachannel
|
|
2
|
+
import nodeDataChannel from './node-datachannel';
|
|
3
|
+
import { WebSocketServerConfiguration } from './types';
|
|
4
|
+
import { WebSocket } from './websocket';
|
|
3
5
|
|
|
4
|
-
export
|
|
5
|
-
#server;
|
|
6
|
-
#clients = [];
|
|
6
|
+
export class WebSocketServer extends EventEmitter {
|
|
7
|
+
#server: any;
|
|
8
|
+
#clients: WebSocket[] = [];
|
|
7
9
|
|
|
8
|
-
constructor(options) {
|
|
10
|
+
constructor(options: WebSocketServerConfiguration) {
|
|
9
11
|
super();
|
|
10
12
|
this.#server = new nodeDataChannel.WebSocketServer(options);
|
|
11
13
|
|
|
@@ -15,11 +17,11 @@ export default class WebSocketServer extends EventEmitter {
|
|
|
15
17
|
});
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
port() {
|
|
20
|
+
port(): number {
|
|
19
21
|
return this.#server?.port() || 0;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
stop() {
|
|
24
|
+
stop(): void {
|
|
23
25
|
this.#clients.forEach((client) => {
|
|
24
26
|
client?.close();
|
|
25
27
|
});
|
|
@@ -28,7 +30,7 @@ export default class WebSocketServer extends EventEmitter {
|
|
|
28
30
|
this.removeAllListeners();
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
onClient(cb) {
|
|
33
|
+
onClient(cb: (clientSocket: WebSocket) => void): void {
|
|
32
34
|
if (this.#server) this.on('client', cb);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import nodeDataChannel from './node-datachannel';
|
|
2
|
+
import { Channel, WebSocketServerConfiguration } from './types';
|
|
3
|
+
|
|
4
|
+
export interface WebSocket extends Channel {
|
|
5
|
+
open(url: string): void;
|
|
6
|
+
forceClose(): void;
|
|
7
|
+
remoteAddress(): string | undefined;
|
|
8
|
+
path(): string | undefined;
|
|
9
|
+
|
|
10
|
+
// Channel implementation
|
|
11
|
+
close(): void;
|
|
12
|
+
sendMessage(msg: string): boolean;
|
|
13
|
+
sendMessageBinary(buffer: Uint8Array): boolean;
|
|
14
|
+
isOpen(): boolean;
|
|
15
|
+
bufferedAmount(): number;
|
|
16
|
+
maxMessageSize(): number;
|
|
17
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
18
|
+
onOpen(cb: () => void): void;
|
|
19
|
+
onClosed(cb: () => void): void;
|
|
20
|
+
onError(cb: (err: string) => void): void;
|
|
21
|
+
onBufferedAmountLow(cb: () => void): void;
|
|
22
|
+
onMessage(cb: (msg: string | Buffer) => void): void;
|
|
23
|
+
}
|
|
24
|
+
export const WebSocket: {
|
|
25
|
+
new(config?: WebSocketServerConfiguration): WebSocket
|
|
26
|
+
} = nodeDataChannel.WebSocket
|