node-datachannel 0.10.1 → 0.11.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.
Files changed (38) hide show
  1. package/.github/workflows/build-win.yml +3 -3
  2. package/.gitmodules +3 -0
  3. package/CMakeLists.txt +1 -1
  4. package/README.md +18 -4
  5. package/examples/client-server/client-benchmark.js +7 -9
  6. package/examples/client-server/client-periodic.js +7 -9
  7. package/examples/client-server/client.js +7 -9
  8. package/examples/client-server/package-lock.json +0 -27
  9. package/examples/client-server/package.json +0 -1
  10. package/examples/client-server/signaling-server.js +21 -10
  11. package/examples/electron-demo/README.md +1 -1
  12. package/examples/websocket/websocket-client.js +20 -0
  13. package/examples/websocket/websocket-server.js +22 -0
  14. package/lib/index.cjs +52 -9
  15. package/lib/index.js +22 -15
  16. package/lib/node-datachannel.js +7 -0
  17. package/lib/websocket-server.js +34 -0
  18. package/package.json +4 -4
  19. package/polyfill/Events.js +5 -3
  20. package/polyfill/Exception.js +23 -0
  21. package/polyfill/README.md +4 -0
  22. package/polyfill/RTCDataChannel.js +19 -11
  23. package/polyfill/RTCPeerConnection.js +148 -41
  24. package/polyfill/index.cjs +252 -59
  25. package/src/peer-connection-wrapper.cpp +11 -3
  26. package/src/web-socket-server-wrapper.cpp +23 -23
  27. package/src/web-socket-server-wrapper.h +8 -6
  28. package/src/web-socket-wrapper.cpp +7 -1
  29. package/test/connectivity.js +1 -23
  30. package/test/wpt-tests/README.md +46 -0
  31. package/test/wpt-tests/chrome-failed-tests.js +42 -0
  32. package/test/wpt-tests/index.js +96 -0
  33. package/test/wpt-tests/last-test-results.md +205 -0
  34. package/test/wpt-tests/package-lock.json +1712 -0
  35. package/test/wpt-tests/package.json +19 -0
  36. package/test/wpt-tests/wpt-test-list.js +137 -0
  37. package/test/wpt-tests/wpt.js +131 -0
  38. package/test/wpt.js +0 -50
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "wpt-tests",
3
+ "version": "1.0.0",
4
+ "description": "git clone https://github.com/web-platform-tests/wpt.git cd wpt ./wpt make-hosts-file | sudo tee -a /etc/hosts ./wpt serve",
5
+ "type": "module",
6
+ "main": "wpt.js",
7
+ "scripts": {
8
+ "test": "npm run run:wpt & (sleep 8 && (npm run run:test > last-test-results.md) )",
9
+ "run:wpt": "cd wpt && ./wpt serve",
10
+ "run:test": "node index.js"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "devDependencies": {
16
+ "jsdom": "^24.1.0",
17
+ "puppeteer": "^22.12.1"
18
+ }
19
+ }
@@ -0,0 +1,137 @@
1
+ export default [
2
+ '/webrtc/getstats.html',
3
+ '/webrtc/historical.html',
4
+ '/webrtc/no-media-call.html',
5
+ '/webrtc/promises-call.html',
6
+ '/webrtc/receiver-track-live.https.html',
7
+ '/webrtc/recvonly-transceiver-can-become-sendrecv.https.html',
8
+ '/webrtc/RollbackEvents.https.html',
9
+ '/webrtc/RTCCertificate.html',
10
+ // // '/webrtc/RTCCertificate-postMessage.html', // SKIP, iframe
11
+ '/webrtc/RTCConfiguration-bundlePolicy.html',
12
+ '/webrtc/RTCConfiguration-iceCandidatePoolSize.html',
13
+ '/webrtc/RTCConfiguration-iceServers.html',
14
+ '/webrtc/RTCConfiguration-iceTransportPolicy.html',
15
+ '/webrtc/RTCConfiguration-rtcpMuxPolicy.html',
16
+ '/webrtc/RTCConfiguration-validation.html',
17
+ '/webrtc/RTCDataChannel-bufferedAmount.html',
18
+ // '/webrtc/RTCDataChannel-close.html', // Not ending
19
+ '/webrtc/RTCDataChannelEvent-constructor.html',
20
+ // '/webrtc/RTCDataChannel-GC.html', // Not ending
21
+ '/webrtc/RTCDataChannel-iceRestart.html',
22
+ '/webrtc/RTCDataChannel-id.html',
23
+ '/webrtc/RTCDataChannel-send-blob-order.html',
24
+ // '/webrtc/RTCDataChannel-send-close.html',
25
+ // '/webrtc/RTCDataChannel-send.html',
26
+ // '/webrtc/RTCDtlsTransport-getRemoteCertificates.html',
27
+ // '/webrtc/RTCDtlsTransport-state.html',
28
+ // '/webrtc/RTCDTMFSender-insertDTMF.https.html',
29
+ // '/webrtc/RTCDTMFSender-ontonechange.https.html',
30
+ // '/webrtc/RTCDTMFSender-ontonechange-long.https.html',
31
+ // '/webrtc/RTCError.html',
32
+ // '/webrtc/RTCIceCandidate-constructor.html',
33
+ // '/webrtc/RTCIceConnectionState-candidate-pair.https.html',
34
+ // '/webrtc/RTCIceTransport.html',
35
+ // '/webrtc/RTCPeerConnection-addIceCandidate-connectionSetup.html',
36
+ '/webrtc/RTCPeerConnection-addIceCandidate.html',
37
+ // '/webrtc/RTCPeerConnection-addIceCandidate-timing.https.html',
38
+ '/webrtc/RTCPeerConnection-addTcpIceCandidate.html',
39
+ // '/webrtc/RTCPeerConnection-addTrack.https.html',
40
+ // '/webrtc/RTCPeerConnection-add-track-no-deadlock.https.html',
41
+ // '/webrtc/RTCPeerConnection-addTransceiver.https.html',
42
+ // '/webrtc/RTCPeerConnection-candidate-in-sdp.https.html',
43
+ // '/webrtc/RTCPeerConnection-canTrickleIceCandidates.html',
44
+ // '/webrtc/RTCPeerConnection-capture-video.https.html',
45
+ // '/webrtc/RTCPeerConnection-connectionState.https.html',
46
+ // '/webrtc/RTCPeerConnection-constructor.html',
47
+ // '/webrtc/RTCPeerConnection-createAnswer.html',
48
+ // '/webrtc/RTCPeerConnection-createDataChannel.html',
49
+ // '/webrtc/RTCPeerConnection-createOffer.html',
50
+ // '/webrtc/RTCPeerConnection-description-attributes-timing.https.html',
51
+ // '/webrtc/RTCPeerConnection-explicit-rollback-iceGatheringState.html',
52
+ // '/webrtc/RTCPeerConnection-GC.https.html',
53
+ // '/webrtc/RTCPeerConnection-generateCertificate.html',
54
+ // '/webrtc/RTCPeerConnection-getStats.https.html',
55
+ // '/webrtc/RTCPeerConnection-getTransceivers.html',
56
+ // '/webrtc/RTCPeerConnection-helper-test.html',
57
+ // '/webrtc/RTCPeerConnection-iceConnectionState-disconnected.https.html',
58
+ // '/webrtc/RTCPeerConnection-iceConnectionState.https.html',
59
+ // '/webrtc/RTCPeerConnectionIceErrorEvent.html',
60
+ // '/webrtc/RTCPeerConnectionIceEvent-constructor.html',
61
+ // '/webrtc/RTCPeerConnection-iceGatheringState.html',
62
+ // '/webrtc/RTCPeerConnection-mandatory-getStats.https.html',
63
+ // '/webrtc/RTCPeerConnection-ondatachannel.html',
64
+ // '/webrtc/RTCPeerConnection-onicecandidateerror.https.html',
65
+ // '/webrtc/RTCPeerConnection-onnegotiationneeded.html',
66
+ // '/webrtc/RTCPeerConnection-onsignalingstatechanged.https.html',
67
+ // '/webrtc/RTCPeerConnection-ontrack.https.html',
68
+ // '/webrtc/RTCPeerConnection-operations.https.html',
69
+ // '/webrtc/RTCPeerConnection-perfect-negotiation.https.html',
70
+ // '/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare.https.html',
71
+ // '/webrtc/RTCPeerConnection-perfect-negotiation-stress-glare-linear.https.html',
72
+ // '/webrtc/RTCPeerConnection-plan-b-is-not-supported.html',
73
+ // '/webrtc/RTCPeerConnection-relay-canvas.https.html',
74
+ // '/webrtc/RTCPeerConnection-remote-track-mute.https.html',
75
+ // '/webrtc/RTCPeerConnection-removeTrack.https.html',
76
+ // '/webrtc/RTCPeerConnection-restartIce.https.html',
77
+ // '/webrtc/RTCPeerConnection-restartIce-onnegotiationneeded.https.html',
78
+ // '/webrtc/RTCPeerConnection-setDescription-transceiver.html',
79
+ // '/webrtc/RTCPeerConnection-setLocalDescription-answer.html',
80
+ // '/webrtc/RTCPeerConnection-setLocalDescription.html',
81
+ // '/webrtc/RTCPeerConnection-setLocalDescription-offer.html',
82
+ // '/webrtc/RTCPeerConnection-setLocalDescription-parameterless.https.html',
83
+ // '/webrtc/RTCPeerConnection-setLocalDescription-pranswer.html',
84
+ // '/webrtc/RTCPeerConnection-setLocalDescription-rollback.html',
85
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-answer.html',
86
+ // '/webrtc/RTCPeerConnection-setRemoteDescription.html',
87
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-nomsid.html',
88
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-offer.html',
89
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-pranswer.html',
90
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-replaceTrack.https.html',
91
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-rollback.html',
92
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-simulcast.https.html',
93
+ // '/webrtc/RTCPeerConnection-setRemoteDescription-tracks.https.html',
94
+ // '/webrtc/RTCPeerConnection-SLD-SRD-timing.https.html',
95
+ // '/webrtc/RTCPeerConnection-transceivers.https.html',
96
+ // '/webrtc/RTCPeerConnection-transport-stats.https.html',
97
+ // '/webrtc/RTCPeerConnection-videoDetectorTest.html',
98
+ // '/webrtc/RTCRtpParameters-codecs.html',
99
+ // '/webrtc/RTCRtpParameters-encodings.html',
100
+ // '/webrtc/RTCRtpParameters-headerExtensions.html',
101
+ // '/webrtc/RTCRtpParameters-maxFramerate.html',
102
+ // '/webrtc/RTCRtpParameters-rtcp.html',
103
+ // '/webrtc/RTCRtpParameters-transactionId.html',
104
+ // '/webrtc/RTCRtpReceiver-audio-jitterBufferTarget-stats.https.html',
105
+ // '/webrtc/RTCRtpReceiver-getCapabilities.html',
106
+ // '/webrtc/RTCRtpReceiver-getContributingSources.https.html',
107
+ // '/webrtc/RTCRtpReceiver-getParameters.html',
108
+ // '/webrtc/RTCRtpReceiver-getStats.https.html',
109
+ // '/webrtc/RTCRtpReceiver-getSynchronizationSources.https.html',
110
+ // '/webrtc/RTCRtpReceiver.https.html',
111
+ // '/webrtc/RTCRtpReceiver-jitterBufferTarget.html',
112
+ // '/webrtc/RTCRtpReceiver-video-jitterBufferTarget-stats.html',
113
+ // '/webrtc/RTCRtpSender-encode-same-track-twice.https.html',
114
+ // '/webrtc/RTCRtpSender-getCapabilities.html',
115
+ // '/webrtc/RTCRtpSender-getParameters.html',
116
+ // '/webrtc/RTCRtpSender-getStats.https.html',
117
+ // '/webrtc/RTCRtpSender.https.html',
118
+ // '/webrtc/RTCRtpSender-replaceTrack.https.html',
119
+ // '/webrtc/RTCRtpSender-setParameters.html',
120
+ // '/webrtc/RTCRtpSender-setParameters-keyFrame.html',
121
+ // '/webrtc/RTCRtpSender-setStreams.https.html',
122
+ // '/webrtc/RTCRtpSender-transport.https.html',
123
+ // '/webrtc/RTCRtpTransceiver-direction.html',
124
+ // '/webrtc/RTCRtpTransceiver.https.html',
125
+ // '/webrtc/RTCRtpTransceiver-setCodecPreferences.html',
126
+ // '/webrtc/RTCRtpTransceiver-stop.html',
127
+ // '/webrtc/RTCRtpTransceiver-stopping.https.html',
128
+ // '/webrtc/RTCSctpTransport-constructor.html',
129
+ // '/webrtc/RTCSctpTransport-events.html',
130
+ // '/webrtc/RTCSctpTransport-maxChannels.html',
131
+ // '/webrtc/RTCSctpTransport-maxMessageSize.html',
132
+ // '/webrtc/RTCTrackEvent-constructor.html',
133
+ // '/webrtc/RTCTrackEvent-fire.html',
134
+ // '/webrtc/simplecall.https.html',
135
+ // '/webrtc/simplecall-no-ssrcs.https.html',
136
+ // '/webrtc/toJSON.html',
137
+ ];
@@ -0,0 +1,131 @@
1
+ // Run WPT manually before calling this script
2
+
3
+ import { JSDOM, VirtualConsole } from 'jsdom';
4
+ import { TextEncoder, TextDecoder } from 'util';
5
+ import puppeteer from 'puppeteer';
6
+ import ndcPolyfill from '../../polyfill/index.js';
7
+
8
+ export async function runWptTests(wptTestList, _forChrome = false, _wptServerUrl = 'http://web-platform.test:8000') {
9
+ let browser;
10
+ let results = [];
11
+
12
+ if (_forChrome)
13
+ browser = await puppeteer.launch({
14
+ headless: true,
15
+ devtools: true,
16
+ });
17
+
18
+ // call runTest for each test path
19
+ for (let i = 0; i < wptTestList.length; i++) {
20
+ console.log(`Running test: ${wptTestList[i]} `);
21
+ const path = `${_wptServerUrl}${wptTestList[i]}`;
22
+ const result = _forChrome ? await runTestForChrome(browser, path) : await runTestForLibrary(path);
23
+ results.push({ test: wptTestList[i], result });
24
+
25
+ // sleep for 1 second
26
+ // await new Promise((resolve) => setTimeout(resolve, 1000));
27
+ }
28
+
29
+ // close the client
30
+ if (_forChrome) await browser.close();
31
+
32
+ return results;
33
+ }
34
+
35
+ function runTestForLibrary(filePath) {
36
+ // return new promise
37
+ return new Promise((resolve, reject) => {
38
+ const virtualConsole = new VirtualConsole();
39
+ virtualConsole.sendTo(console);
40
+
41
+ JSDOM.fromURL(filePath, {
42
+ runScripts: 'dangerously',
43
+ resources: 'usable',
44
+ pretendToBeVisual: true,
45
+ virtualConsole,
46
+ beforeParse(window) {
47
+ // Assign the polyfill to the window object
48
+ Object.assign(window, ndcPolyfill);
49
+
50
+ // Overwrite the DOMException object
51
+ window.DOMException = DOMException;
52
+ window.TypeError = TypeError;
53
+ window.TextEncoder = TextEncoder;
54
+ window.TextDecoder = TextDecoder;
55
+ window.Uint8Array = Uint8Array;
56
+ window.ArrayBuffer = ArrayBuffer;
57
+ },
58
+ }).then((dom) => {
59
+ // Get the window object from the DOM
60
+ const { window } = dom;
61
+ window.addEventListener('load', () => {
62
+ window.add_completion_callback((results) => {
63
+ window.close();
64
+
65
+ // Meaning of status
66
+ // 0: PASS (test passed)
67
+ // 1: FAIL (test failed)
68
+ // 2: TIMEOUT (test timed out)
69
+ // 3: PRECONDITION_FAILED (test skipped)
70
+ const returnObject = [];
71
+ for (let i = 0; i < results.length; i++) {
72
+ returnObject.push({
73
+ name: results[i].name,
74
+ message: results[i].message,
75
+ status: results[i].status,
76
+ });
77
+ }
78
+ return resolve(returnObject);
79
+ });
80
+ });
81
+ });
82
+ });
83
+ }
84
+
85
+ async function runTestForChrome(browser, filePath) {
86
+ const page = await browser.newPage();
87
+ // Evaluate the script in the page context
88
+ await page.evaluateOnNewDocument(() => {
89
+ function createDeferredPromise() {
90
+ let resolve, reject;
91
+
92
+ let promise = new Promise(function (_resolve, _reject) {
93
+ resolve = _resolve;
94
+ reject = _reject;
95
+ });
96
+
97
+ promise.resolve = resolve;
98
+ promise.reject = reject;
99
+ return promise;
100
+ }
101
+
102
+ window.addEventListener('load', () => {
103
+ window.resultPromise = createDeferredPromise();
104
+ window.add_completion_callback((results) => {
105
+ // window.returnTestResults.push({ name: test.name, message: test.message, status: test.status });
106
+ let returnTestResults = [];
107
+ for (let i = 0; i < results.length; i++) {
108
+ returnTestResults.push({
109
+ name: results[i].name,
110
+ message: results[i].message,
111
+ status: results[i].status,
112
+ });
113
+ }
114
+ window.resultPromise.resolve(returnTestResults);
115
+ });
116
+ });
117
+ });
118
+
119
+ // Navigate to the specified URL
120
+ await page.goto(filePath, { waitUntil: 'load' });
121
+
122
+ // get the results
123
+ const results = await page.evaluate(() => {
124
+ return window.resultPromise;
125
+ });
126
+
127
+ // close the page
128
+ await page.close();
129
+
130
+ return results;
131
+ }
package/test/wpt.js DELETED
@@ -1,50 +0,0 @@
1
- // RUn WPT manually before calling this script
2
- // Example: ./wpt serve
3
- // Example: node test/wpt.js
4
-
5
- import { JSDOM } from 'jsdom';
6
- import nodeDataChannel from '../lib/index.js';
7
-
8
- const WPT_SERVER_URL = 'http://web-platform.test:8000';
9
- const WPT_TEST_PATH_LIST = ['/webrtc/RTCPeerConnection-addIceCandidate.html', '/webrtc/RTCDataChannel-send.html'];
10
-
11
- // call runTest for each test path
12
- for (let i = 0; i < WPT_TEST_PATH_LIST.length; i++) {
13
- let result = await runTest(`${WPT_SERVER_URL}${WPT_TEST_PATH_LIST[i]}`);
14
- console.log(result);
15
-
16
- // sleep for 1 second
17
- await new Promise((resolve) => setTimeout(resolve, 1000));
18
- }
19
-
20
- function runTest(filePath) {
21
- // return new promise
22
- return new Promise((resolve, reject) => {
23
- JSDOM.fromURL(filePath, {
24
- runScripts: 'dangerously',
25
- resources: 'usable',
26
- }).then((dom) => {
27
- const { window } = dom;
28
-
29
- // Assign the data channel polyfill to the window object
30
- Object.assign(window, nodeDataChannel);
31
-
32
- const returnObject = [];
33
- window.addEventListener('load', () => {
34
- window.add_result_callback((test) => {
35
- // Meaning of status
36
- // 0: PASS (test passed)
37
- // 1: FAIL (test failed)
38
- // 2: TIMEOUT (test timed out)
39
- // 3: PRECONDITION_FAILED (test skipped)
40
- returnObject.push({ name: test.name, message: test.message, status: test.status });
41
- });
42
-
43
- window.add_completion_callback(() => {
44
- window.close();
45
- return resolve(returnObject);
46
- });
47
- });
48
- });
49
- });
50
- }