node-datachannel 0.11.0 → 0.20.0-alpha.1
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/jest.config.ts +14 -0
- package/package.json +47 -44
- 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/src/polyfill/RTCIceCandidate.ts +125 -0
- package/{polyfill/RTCIceTransport.js → src/polyfill/RTCIceTransport.ts} +22 -20
- package/{polyfill/RTCPeerConnection.js → src/polyfill/RTCPeerConnection.ts} +137 -115
- 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} +12 -9
- package/tsconfig.json +20 -13
- package/.eslintrc.cjs +0 -8
- package/.github/FUNDING.yml +0 -2
- package/.github/workflows/build-linux.yml +0 -104
- 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 -15933
- package/examples/electron-demo/package.json +0 -43
- 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 -11
- 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/RTCIceCandidate.d.ts +0 -20
- package/polyfill/RTCIceCandidate.js +0 -126
- 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 -1258
- package/polyfill/index.d.cts +0 -37
- package/polyfill/index.d.ts +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 -205
- 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 -137
- 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/.eslintignore
CHANGED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": false,
|
|
4
|
+
"es6": true,
|
|
5
|
+
"node": true
|
|
6
|
+
},
|
|
7
|
+
"parser": "@typescript-eslint/parser",
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"project": "tsconfig.json",
|
|
10
|
+
"sourceType": "module",
|
|
11
|
+
"ecmaVersion": 2020
|
|
12
|
+
},
|
|
13
|
+
"plugins": ["@typescript-eslint", "jest"],
|
|
14
|
+
"extends": [
|
|
15
|
+
"eslint:recommended",
|
|
16
|
+
"plugin:@typescript-eslint/recommended",
|
|
17
|
+
"plugin:jest/recommended",
|
|
18
|
+
"prettier"
|
|
19
|
+
],
|
|
20
|
+
"rules": {
|
|
21
|
+
// The following rule is enabled only to supplement the inline suppression
|
|
22
|
+
// examples, and because it is not a recommended rule, you should either
|
|
23
|
+
// disable it, or understand what it enforces.
|
|
24
|
+
// https://typescript-eslint.io/rules/explicit-function-return-type/
|
|
25
|
+
"@typescript-eslint/explicit-function-return-type": "warn"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/.prettierrc
ADDED
package/CMakeLists.txt
CHANGED
|
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
|
|
2
2
|
cmake_policy(SET CMP0091 NEW)
|
|
3
3
|
cmake_policy(SET CMP0042 NEW)
|
|
4
4
|
|
|
5
|
-
project(node_datachannel VERSION 0.
|
|
5
|
+
project(node_datachannel VERSION 0.20.0)
|
|
6
6
|
|
|
7
7
|
# -Dnapi_build_version=8
|
|
8
8
|
add_definitions(-DNAPI_VERSION=8)
|
|
@@ -43,18 +43,18 @@ if(NOT libdatachannel)
|
|
|
43
43
|
endif()
|
|
44
44
|
|
|
45
45
|
add_library(${PROJECT_NAME} SHARED
|
|
46
|
-
src/rtc-wrapper.cpp
|
|
47
|
-
src/media-direction.cpp
|
|
48
|
-
src/media-rtcpreceivingsession-wrapper.cpp
|
|
49
|
-
src/media-track-wrapper.cpp
|
|
50
|
-
src/media-audio-wrapper.cpp
|
|
51
|
-
src/media-video-wrapper.cpp
|
|
52
|
-
src/data-channel-wrapper.cpp
|
|
53
|
-
src/peer-connection-wrapper.cpp
|
|
54
|
-
src/thread-safe-callback.cpp
|
|
55
|
-
src/web-socket-wrapper.cpp
|
|
56
|
-
src/web-socket-server-wrapper.cpp
|
|
57
|
-
src/main.cpp
|
|
46
|
+
src/cpp/rtc-wrapper.cpp
|
|
47
|
+
src/cpp/media-direction.cpp
|
|
48
|
+
src/cpp/media-rtcpreceivingsession-wrapper.cpp
|
|
49
|
+
src/cpp/media-track-wrapper.cpp
|
|
50
|
+
src/cpp/media-audio-wrapper.cpp
|
|
51
|
+
src/cpp/media-video-wrapper.cpp
|
|
52
|
+
src/cpp/data-channel-wrapper.cpp
|
|
53
|
+
src/cpp/peer-connection-wrapper.cpp
|
|
54
|
+
src/cpp/thread-safe-callback.cpp
|
|
55
|
+
src/cpp/web-socket-wrapper.cpp
|
|
56
|
+
src/cpp/web-socket-server-wrapper.cpp
|
|
57
|
+
src/cpp/main.cpp
|
|
58
58
|
${CMAKE_JS_SRC}
|
|
59
59
|
)
|
|
60
60
|
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Config } from 'jest';
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
clearMocks: true,
|
|
5
|
+
collectCoverage: false,
|
|
6
|
+
coverageDirectory: "coverage",
|
|
7
|
+
coverageProvider: "v8",
|
|
8
|
+
preset: 'ts-jest',
|
|
9
|
+
testEnvironment: "jest-environment-node",
|
|
10
|
+
testRegex: '(/test/jest-tests/.*|(\\.|/)(test|spec))\\.(m)?ts$',
|
|
11
|
+
testPathIgnorePatterns: ['node_modules', 'multiple-run.test'],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,52 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-datachannel",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "libdatachannel node bindings",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.20.0-alpha.1",
|
|
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"
|
|
50
42
|
},
|
|
51
43
|
"binary": {
|
|
52
44
|
"napi_versions": [
|
|
@@ -82,22 +74,33 @@
|
|
|
82
74
|
},
|
|
83
75
|
"homepage": "https://github.com/murat-dogan/node-datachannel#readme",
|
|
84
76
|
"devDependencies": {
|
|
77
|
+
"@rollup/plugin-esm-shim": "^0.1.7",
|
|
78
|
+
"@types/jest": "^29.5.12",
|
|
85
79
|
"@types/node": "^20.6.1",
|
|
86
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
87
|
-
"@typescript-eslint/parser": "^
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "^7.17.0",
|
|
81
|
+
"@typescript-eslint/parser": "^7.17.0",
|
|
88
82
|
"cmake-js": "^6.3.2",
|
|
89
|
-
"eslint": "^8.
|
|
90
|
-
"eslint-config-prettier": "^
|
|
91
|
-
"eslint-plugin-
|
|
83
|
+
"eslint": "^8.57.0",
|
|
84
|
+
"eslint-config-prettier": "^9.1.0",
|
|
85
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
86
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
92
87
|
"jest": "^29.7.0",
|
|
88
|
+
"jsdom": "^24.1.1",
|
|
93
89
|
"node-addon-api": "^7.0.0",
|
|
94
90
|
"prebuild": "^12.0.0",
|
|
95
|
-
"prettier": "^
|
|
96
|
-
"
|
|
97
|
-
"
|
|
91
|
+
"prettier": "^3.3.3",
|
|
92
|
+
"puppeteer": "^22.14.0",
|
|
93
|
+
"rimraf": "^5.0.9",
|
|
94
|
+
"rollup": "^4.22.5",
|
|
95
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
96
|
+
"rollup-plugin-esbuild": "^6.1.1",
|
|
97
|
+
"ts-api-utils": "^1.3.0",
|
|
98
|
+
"ts-jest": "^29.2.3",
|
|
99
|
+
"ts-node": "^10.9.2",
|
|
100
|
+
"typescript": "5.4"
|
|
98
101
|
},
|
|
99
102
|
"dependencies": {
|
|
100
103
|
"node-domexception": "^2.0.1",
|
|
101
104
|
"prebuild-install": "^7.0.1"
|
|
102
105
|
}
|
|
103
|
-
}
|
|
106
|
+
}
|
|
@@ -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
|
+
|