node-datachannel 0.10.1 → 0.12.0
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/.github/workflows/build-linux.yml +7 -2
- package/.github/workflows/build-win.yml +3 -3
- package/.gitmodules +3 -0
- package/CMakeLists.txt +1 -1
- package/README.md +18 -4
- package/cmake/toolchain/ci.cmake +1 -1
- package/examples/client-server/client-benchmark.js +7 -9
- package/examples/client-server/client-periodic.js +7 -9
- package/examples/client-server/client.js +7 -9
- package/examples/client-server/package-lock.json +0 -27
- package/examples/client-server/package.json +0 -1
- package/examples/client-server/signaling-server.js +21 -10
- package/examples/electron-demo/README.md +1 -1
- package/examples/electron-demo/package-lock.json +316 -372
- package/examples/electron-demo/package.json +2 -1
- package/examples/electron-demo/webpack.main.config.js +10 -0
- package/examples/websocket/websocket-client.js +20 -0
- package/examples/websocket/websocket-server.js +22 -0
- package/jest.config.cjs +1 -1
- package/lib/index.cjs +52 -9
- package/lib/index.js +22 -15
- package/lib/node-datachannel.js +7 -0
- package/lib/websocket-server.js +34 -0
- package/package.json +3 -3
- package/polyfill/Events.js +5 -3
- package/polyfill/Exception.js +23 -0
- package/polyfill/README.md +4 -0
- package/polyfill/RTCDataChannel.js +19 -11
- package/polyfill/RTCError.d.ts +11 -0
- package/polyfill/RTCError.js +65 -0
- package/polyfill/RTCIceCandidate.js +22 -23
- package/polyfill/RTCPeerConnection.js +157 -42
- package/polyfill/index.cjs +350 -82
- package/polyfill/index.js +3 -0
- package/src/peer-connection-wrapper.cpp +11 -3
- package/src/web-socket-server-wrapper.cpp +23 -23
- package/src/web-socket-server-wrapper.h +8 -6
- package/src/web-socket-wrapper.cpp +7 -1
- package/test/connectivity.js +1 -23
- package/test/wpt-tests/README.md +46 -0
- package/test/wpt-tests/chrome-failed-tests.js +42 -0
- package/test/wpt-tests/index.js +96 -0
- package/test/wpt-tests/last-test-results.md +301 -0
- package/test/wpt-tests/package-lock.json +1712 -0
- package/test/wpt-tests/package.json +19 -0
- package/test/wpt-tests/wpt-test-list.js +139 -0
- package/test/wpt-tests/wpt.js +131 -0
- package/test/wpt.js +0 -50
|
@@ -25,6 +25,7 @@ jobs:
|
|
|
25
25
|
libc: musl
|
|
26
26
|
gcc_install: clang lld
|
|
27
27
|
gcc: clang
|
|
28
|
+
gxx: clang++
|
|
28
29
|
# libc is intentionally not set here, as prebuild-install requires libc to not be set for glibc builds
|
|
29
30
|
- triple: "linux-gnu"
|
|
30
31
|
platform: debian
|
|
@@ -43,15 +44,17 @@ jobs:
|
|
|
43
44
|
arch: arm64
|
|
44
45
|
flags: -march=armv8-a -fPIC
|
|
45
46
|
# Set edge case overrides for specific platform + architecture
|
|
46
|
-
# also define gcc commands for each architecture
|
|
47
|
+
# also define gcc commands for each architecture
|
|
47
48
|
- arch: amd64
|
|
48
49
|
platform: debian
|
|
49
50
|
gcc_install: gcc g++
|
|
50
51
|
gcc: gcc
|
|
52
|
+
gxx: g++
|
|
51
53
|
- arch: arm64
|
|
52
54
|
platform: debian
|
|
53
55
|
gcc_install: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
|
|
54
56
|
gcc: aarch64-linux-gnu-gcc
|
|
57
|
+
gxx: aarch64-linux-gnu-g++
|
|
55
58
|
# debian uses the triple `arm-linux-gnueabihf` instead of alpine's `armv7-alpine-linux-musleabihf`
|
|
56
59
|
# because of this, we explicitly override triple_arch for debian arm
|
|
57
60
|
- triple_arch: arm
|
|
@@ -59,6 +62,7 @@ jobs:
|
|
|
59
62
|
platform: debian
|
|
60
63
|
gcc_install: gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
|
|
61
64
|
gcc: arm-linux-gnueabihf-gcc
|
|
65
|
+
gxx: arm-linux-gnueabihf-g++
|
|
62
66
|
|
|
63
67
|
steps:
|
|
64
68
|
- uses: actions/checkout@v4
|
|
@@ -87,13 +91,14 @@ jobs:
|
|
|
87
91
|
id: sysroot
|
|
88
92
|
run: echo "sysroot=$(sudo podman image mount ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }})" >> $GITHUB_OUTPUT
|
|
89
93
|
- name: Build
|
|
90
|
-
run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.node_arch }} -r napi --backend cmake-js -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake
|
|
94
|
+
run: sudo --preserve-env=SYSROOT,TRIPLE,COMPILER_FLAGS,LIBC,GCC,GXX,CI,PATH node_modules/.bin/prebuild --arch ${{ matrix.node_arch }} -r napi --backend cmake-js -- --CDCMAKE_TOOLCHAIN_FILE:FILEPATH=./cmake/toolchain/ci.cmake
|
|
91
95
|
env:
|
|
92
96
|
SYSROOT: ${{ steps.sysroot.outputs.sysroot }}
|
|
93
97
|
TRIPLE: ${{ matrix.triple_arch }}-${{ matrix.triple }}${{ matrix.triple_postfix }}
|
|
94
98
|
COMPILER_FLAGS: ${{ matrix.flags }}
|
|
95
99
|
LIBC: ${{ matrix.libc }}
|
|
96
100
|
GCC: ${{ matrix.gcc }}
|
|
101
|
+
GXX: ${{ matrix.gxx }}
|
|
97
102
|
CI: true
|
|
98
103
|
- name: Test
|
|
99
104
|
run: sudo podman run --rm -v $(pwd):/usr/app/ -e CI=true --platform linux/${{ matrix.arch }} -t ndc-buildroot:${{ matrix.platform }}-${{ matrix.arch }} npm run test
|
|
@@ -17,12 +17,12 @@ jobs:
|
|
|
17
17
|
node-version: [16.x]
|
|
18
18
|
|
|
19
19
|
steps:
|
|
20
|
-
- uses: actions/checkout@
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
21
|
- uses: ilammy/msvc-dev-cmd@v1
|
|
22
22
|
- name: Install OpenSSL
|
|
23
23
|
run: choco install openssl
|
|
24
24
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
25
|
-
uses: actions/setup-node@
|
|
25
|
+
uses: actions/setup-node@v4
|
|
26
26
|
with:
|
|
27
27
|
node-version: ${{ matrix.node-version }}
|
|
28
28
|
- name: Build
|
|
@@ -46,7 +46,7 @@ jobs:
|
|
|
46
46
|
node_arch:
|
|
47
47
|
- x86
|
|
48
48
|
steps:
|
|
49
|
-
- uses: actions/checkout@
|
|
49
|
+
- uses: actions/checkout@v4
|
|
50
50
|
- uses: ilammy/msvc-dev-cmd@v1
|
|
51
51
|
with:
|
|
52
52
|
arch: x86
|
package/.gitmodules
ADDED
package/CMakeLists.txt
CHANGED
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
# WebRTC For Node.js and Electron
|
|
1
|
+
# WebRTC For Node.js and Electron ( with WebSocket)
|
|
2
2
|
|
|
3
3
|
   
|
|
4
4
|
|
|
5
5
|
- Lightweight
|
|
6
6
|
- No need to deal with WebRTC stack!
|
|
7
|
-
- Small binary sizes (~8MB for Linux
|
|
7
|
+
- Small binary sizes (~8MB for Linux x64)
|
|
8
8
|
- Type infos for Typescript
|
|
9
|
+
- Integrated WebSocket Client & Server Implementation
|
|
9
10
|
|
|
10
11
|
This project is Node.js bindings for [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library.
|
|
11
12
|
|
|
@@ -35,7 +36,17 @@ Please check [electron demo](/examples/electron-demo)
|
|
|
35
36
|
|
|
36
37
|
WebRTC polyfills to be used for libraries like `simple-peer`.
|
|
37
38
|
|
|
38
|
-
Please check [here](/polyfill)
|
|
39
|
+
Please check [here for more](/polyfill)
|
|
40
|
+
|
|
41
|
+
### web-platform-tests
|
|
42
|
+
|
|
43
|
+
Please check actual situation [here](/test/wpt-tests/)
|
|
44
|
+
|
|
45
|
+
## WebSocket Client & Server
|
|
46
|
+
|
|
47
|
+
Integrated WebSocket Client & Server is available, which can be used separately or for signaling.
|
|
48
|
+
|
|
49
|
+
For an example usage, [check here](/examples/websocket)
|
|
39
50
|
|
|
40
51
|
## Example Usage
|
|
41
52
|
|
|
@@ -45,6 +56,9 @@ import nodeDataChannel from 'node-datachannel';
|
|
|
45
56
|
// Log Level
|
|
46
57
|
nodeDataChannel.initLogger('Debug');
|
|
47
58
|
|
|
59
|
+
// Integrated WebSocket available and can be used for signaling etc
|
|
60
|
+
// const ws = new nodeDataChannel.WebSocket();
|
|
61
|
+
|
|
48
62
|
let dc1 = null;
|
|
49
63
|
let dc2 = null;
|
|
50
64
|
|
|
@@ -105,7 +119,7 @@ Please check [docs](/API.md) page
|
|
|
105
119
|
|
|
106
120
|
## Contributing
|
|
107
121
|
|
|
108
|
-
Contributions welcome!
|
|
122
|
+
Contributions are welcome!
|
|
109
123
|
|
|
110
124
|
## Thanks
|
|
111
125
|
|
package/cmake/toolchain/ci.cmake
CHANGED
|
@@ -6,7 +6,6 @@ const require = createRequire(import.meta.url);
|
|
|
6
6
|
const yargs = require('yargs/yargs');
|
|
7
7
|
const { hideBin } = require('yargs/helpers');
|
|
8
8
|
|
|
9
|
-
import WebSocket from 'ws';
|
|
10
9
|
import readline from 'readline';
|
|
11
10
|
import nodeDataChannel from '../../lib/index.js';
|
|
12
11
|
|
|
@@ -60,23 +59,22 @@ const rl = readline.createInterface({
|
|
|
60
59
|
output: process.stdout,
|
|
61
60
|
});
|
|
62
61
|
|
|
63
|
-
const ws = new WebSocket(
|
|
64
|
-
|
|
65
|
-
});
|
|
62
|
+
const ws = new nodeDataChannel.WebSocket();
|
|
63
|
+
ws.open(wsUrl + '/' + id);
|
|
66
64
|
|
|
67
65
|
console.log(`The local ID is: ${id}`);
|
|
68
66
|
console.log(`Waiting for signaling to be connected...`);
|
|
69
67
|
|
|
70
|
-
ws.
|
|
68
|
+
ws.onOpen(() => {
|
|
71
69
|
console.log('WebSocket connected, signaling ready');
|
|
72
70
|
readUserInput();
|
|
73
71
|
});
|
|
74
72
|
|
|
75
|
-
ws.
|
|
73
|
+
ws.onError((err) => {
|
|
76
74
|
console.log('WebSocket Error: ', err);
|
|
77
75
|
});
|
|
78
76
|
|
|
79
|
-
ws.
|
|
77
|
+
ws.onMessage((msgStr) => {
|
|
80
78
|
let msg = JSON.parse(msgStr);
|
|
81
79
|
switch (msg.type) {
|
|
82
80
|
case 'offer':
|
|
@@ -184,10 +182,10 @@ function createPeerConnection(peerId) {
|
|
|
184
182
|
console.log('GatheringState: ', state);
|
|
185
183
|
});
|
|
186
184
|
peerConnection.onLocalDescription((description, type) => {
|
|
187
|
-
ws.
|
|
185
|
+
ws.sendMessage(JSON.stringify({ id: peerId, type, description }));
|
|
188
186
|
});
|
|
189
187
|
peerConnection.onLocalCandidate((candidate, mid) => {
|
|
190
|
-
ws.
|
|
188
|
+
ws.sendMessage(JSON.stringify({ id: peerId, type: 'candidate', candidate, mid }));
|
|
191
189
|
});
|
|
192
190
|
peerConnection.onDataChannel((dc) => {
|
|
193
191
|
rl.close();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
1
|
import readline from 'readline';
|
|
3
2
|
import nodeDataChannel from '../../lib/index.js';
|
|
4
3
|
|
|
@@ -25,23 +24,22 @@ const rl = readline.createInterface({
|
|
|
25
24
|
|
|
26
25
|
// Signaling Server
|
|
27
26
|
const WS_URL = process.env.WS_URL || 'ws://localhost:8000';
|
|
28
|
-
const ws = new WebSocket(
|
|
29
|
-
|
|
30
|
-
});
|
|
27
|
+
const ws = new nodeDataChannel.WebSocket();
|
|
28
|
+
ws.open(WS_URL + '/' + id);
|
|
31
29
|
|
|
32
30
|
console.log(`The local ID is: ${id}`);
|
|
33
31
|
console.log(`Waiting for signaling to be connected...`);
|
|
34
32
|
|
|
35
|
-
ws.
|
|
33
|
+
ws.onOpen(() => {
|
|
36
34
|
console.log('WebSocket connected, signaling ready');
|
|
37
35
|
readUserInput();
|
|
38
36
|
});
|
|
39
37
|
|
|
40
|
-
ws.
|
|
38
|
+
ws.onError((err) => {
|
|
41
39
|
console.log('WebSocket Error: ', err);
|
|
42
40
|
});
|
|
43
41
|
|
|
44
|
-
ws.
|
|
42
|
+
ws.onMessage((msgStr) => {
|
|
45
43
|
let msg = JSON.parse(msgStr);
|
|
46
44
|
switch (msg.type) {
|
|
47
45
|
case 'offer':
|
|
@@ -122,10 +120,10 @@ function createPeerConnection(peerId) {
|
|
|
122
120
|
console.log('GatheringState: ', state);
|
|
123
121
|
});
|
|
124
122
|
peerConnection.onLocalDescription((description, type) => {
|
|
125
|
-
ws.
|
|
123
|
+
ws.sendMessage(JSON.stringify({ id: peerId, type, description }));
|
|
126
124
|
});
|
|
127
125
|
peerConnection.onLocalCandidate((candidate, mid) => {
|
|
128
|
-
ws.
|
|
126
|
+
ws.sendMessage(JSON.stringify({ id: peerId, type: 'candidate', candidate, mid }));
|
|
129
127
|
});
|
|
130
128
|
peerConnection.onDataChannel((dc) => {
|
|
131
129
|
rl.close();
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import WebSocket from 'ws';
|
|
2
1
|
import readline from 'readline';
|
|
3
2
|
import nodeDataChannel from '../../lib/index.js';
|
|
4
3
|
|
|
@@ -13,23 +12,22 @@ const id = randomId(4);
|
|
|
13
12
|
|
|
14
13
|
// Signaling Server
|
|
15
14
|
const WS_URL = process.env.WS_URL || 'ws://localhost:8000';
|
|
16
|
-
const ws = new WebSocket(
|
|
17
|
-
|
|
18
|
-
});
|
|
15
|
+
const ws = new nodeDataChannel.WebSocket();
|
|
16
|
+
ws.open(WS_URL + '/' + id);
|
|
19
17
|
|
|
20
18
|
console.log(`The local ID is: ${id}`);
|
|
21
19
|
console.log(`Waiting for signaling to be connected...`);
|
|
22
20
|
|
|
23
|
-
ws.
|
|
21
|
+
ws.onOpen(() => {
|
|
24
22
|
console.log('WebSocket connected, signaling ready');
|
|
25
23
|
readUserInput();
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
ws.
|
|
26
|
+
ws.onError((err) => {
|
|
29
27
|
console.log('WebSocket Error: ', err);
|
|
30
28
|
});
|
|
31
29
|
|
|
32
|
-
ws.
|
|
30
|
+
ws.onMessage((msgStr) => {
|
|
33
31
|
let msg = JSON.parse(msgStr);
|
|
34
32
|
switch (msg.type) {
|
|
35
33
|
case 'offer':
|
|
@@ -86,10 +84,10 @@ function createPeerConnection(peerId) {
|
|
|
86
84
|
console.log('GatheringState: ', state);
|
|
87
85
|
});
|
|
88
86
|
peerConnection.onLocalDescription((description, type) => {
|
|
89
|
-
ws.
|
|
87
|
+
ws.sendMessage(JSON.stringify({ id: peerId, type, description }));
|
|
90
88
|
});
|
|
91
89
|
peerConnection.onLocalCandidate((candidate, mid) => {
|
|
92
|
-
ws.
|
|
90
|
+
ws.sendMessage(JSON.stringify({ id: peerId, type: 'candidate', candidate, mid }));
|
|
93
91
|
});
|
|
94
92
|
peerConnection.onDataChannel((dc) => {
|
|
95
93
|
console.log('DataChannel from ' + peerId + ' received with label "', dc.getLabel() + '"');
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"ws": "^7.5.3",
|
|
13
12
|
"yargs": "^16.2.0"
|
|
14
13
|
}
|
|
15
14
|
},
|
|
@@ -138,26 +137,6 @@
|
|
|
138
137
|
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
|
139
138
|
}
|
|
140
139
|
},
|
|
141
|
-
"node_modules/ws": {
|
|
142
|
-
"version": "7.5.10",
|
|
143
|
-
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
|
144
|
-
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
|
145
|
-
"engines": {
|
|
146
|
-
"node": ">=8.3.0"
|
|
147
|
-
},
|
|
148
|
-
"peerDependencies": {
|
|
149
|
-
"bufferutil": "^4.0.1",
|
|
150
|
-
"utf-8-validate": "^5.0.2"
|
|
151
|
-
},
|
|
152
|
-
"peerDependenciesMeta": {
|
|
153
|
-
"bufferutil": {
|
|
154
|
-
"optional": true
|
|
155
|
-
},
|
|
156
|
-
"utf-8-validate": {
|
|
157
|
-
"optional": true
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
140
|
"node_modules/y18n": {
|
|
162
141
|
"version": "5.0.8",
|
|
163
142
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
|
@@ -282,12 +261,6 @@
|
|
|
282
261
|
"strip-ansi": "^6.0.0"
|
|
283
262
|
}
|
|
284
263
|
},
|
|
285
|
-
"ws": {
|
|
286
|
-
"version": "7.5.10",
|
|
287
|
-
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
|
288
|
-
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
|
289
|
-
"requires": {}
|
|
290
|
-
},
|
|
291
264
|
"y18n": {
|
|
292
265
|
"version": "5.0.8",
|
|
293
266
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import nodeDataChannel from '../../lib/index.js';
|
|
2
|
+
|
|
3
|
+
// Init Logger
|
|
4
|
+
nodeDataChannel.initLogger('Debug');
|
|
2
5
|
|
|
3
6
|
const clients = {};
|
|
4
7
|
|
|
5
|
-
const
|
|
8
|
+
const wsServer = new nodeDataChannel.WebSocketServer({ bindAddress: '127.0.0.1', port: 8000 });
|
|
9
|
+
|
|
10
|
+
wsServer.onClient((ws) => {
|
|
11
|
+
let id = '';
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
ws.onOpen(() => {
|
|
14
|
+
id = ws.path().replace('/', '');
|
|
15
|
+
console.log(`New Connection from ${id}`);
|
|
16
|
+
clients[id] = ws;
|
|
17
|
+
});
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
ws.on('message', (buffer) => {
|
|
19
|
+
ws.onMessage((buffer) => {
|
|
13
20
|
let msg = JSON.parse(buffer);
|
|
14
21
|
let peerId = msg.id;
|
|
15
22
|
let peerWs = clients[peerId];
|
|
@@ -18,11 +25,15 @@ wss.on('connection', (ws, req) => {
|
|
|
18
25
|
if (!peerWs) return console.error(`Can not find peer with ID ${peerId}`);
|
|
19
26
|
|
|
20
27
|
msg.id = id;
|
|
21
|
-
peerWs.
|
|
28
|
+
peerWs.sendMessage(JSON.stringify(msg));
|
|
22
29
|
});
|
|
23
30
|
|
|
24
|
-
ws.
|
|
25
|
-
console.log(`${id}
|
|
31
|
+
ws.onClosed(() => {
|
|
32
|
+
console.log(`${id} disconnected`);
|
|
26
33
|
delete clients[id];
|
|
27
34
|
});
|
|
35
|
+
|
|
36
|
+
ws.onError((err) => {
|
|
37
|
+
console.error(err);
|
|
38
|
+
});
|
|
28
39
|
});
|
|
@@ -6,7 +6,7 @@ Project created with
|
|
|
6
6
|
|
|
7
7
|
## Electron Compatibility and Rebuilding
|
|
8
8
|
|
|
9
|
-
`node-datachannel` uses N-API for creating binaries. Normally `electron` is compatible with N-API
|
|
9
|
+
`node-datachannel` uses N-API for creating binaries. Normally `electron` is compatible with N-API binaries, so you should not need to rebuild the binaries.
|
|
10
10
|
|
|
11
11
|
### If you need anyway, you can use `electron-rebuild` package with some modifications.
|
|
12
12
|
|