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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// https://developer.mozilla.org/docs/Web/API/RTCIceCandidate
|
|
2
|
+
//
|
|
3
|
+
// Example: candidate:123456 1 UDP 123456 192.168.1.1 12345 typ host raddr=10.0.0.1 rport=54321 generation 0
|
|
4
|
+
|
|
5
|
+
import 'node-domexception';
|
|
6
|
+
|
|
7
|
+
export default class RTCIceCandidate implements globalThis.RTCIceCandidate {
|
|
8
|
+
#address: string | null;
|
|
9
|
+
#candidate: string;
|
|
10
|
+
#component: globalThis.RTCIceComponent | null;
|
|
11
|
+
#foundation: string | null;
|
|
12
|
+
#port: number | null;
|
|
13
|
+
#priority: number | null;
|
|
14
|
+
#protocol: globalThis.RTCIceProtocol | null;
|
|
15
|
+
#relatedAddress: string | null;
|
|
16
|
+
#relatedPort: number | null;
|
|
17
|
+
#sdpMLineIndex: number | null;
|
|
18
|
+
#sdpMid: string | null;
|
|
19
|
+
#tcpType: globalThis.RTCIceTcpCandidateType | null;
|
|
20
|
+
#type: globalThis.RTCIceCandidateType | null;
|
|
21
|
+
#usernameFragment: string | null;
|
|
22
|
+
|
|
23
|
+
constructor({ candidate, sdpMLineIndex, sdpMid, usernameFragment }: globalThis.RTCIceCandidateInit) {
|
|
24
|
+
if (sdpMLineIndex == null && sdpMid == null)
|
|
25
|
+
throw new TypeError('At least one of sdpMLineIndex or sdpMid must be specified');
|
|
26
|
+
|
|
27
|
+
this.#candidate = candidate === null ? 'null' : candidate ?? '';
|
|
28
|
+
this.#sdpMLineIndex = sdpMLineIndex ?? null;
|
|
29
|
+
this.#sdpMid = sdpMid ?? null;
|
|
30
|
+
this.#usernameFragment = usernameFragment ?? null;
|
|
31
|
+
|
|
32
|
+
if (candidate) {
|
|
33
|
+
const fields = candidate.split(' ');
|
|
34
|
+
this.#foundation = fields[0].replace('candidate:', ''); // remove text candidate:
|
|
35
|
+
this.#component = fields[1] == '1' ? 'rtp' : 'rtcp';
|
|
36
|
+
this.#protocol = fields[2] as globalThis.RTCIceProtocol;
|
|
37
|
+
this.#priority = parseInt(fields[3], 10);
|
|
38
|
+
this.#address = fields[4];
|
|
39
|
+
this.#port = parseInt(fields[5], 10);
|
|
40
|
+
this.#type = fields[7] as globalThis.RTCIceCandidateType;
|
|
41
|
+
this.#tcpType = null;
|
|
42
|
+
this.#relatedAddress = null;
|
|
43
|
+
this.#relatedPort = null;
|
|
44
|
+
|
|
45
|
+
// Parse the candidate string to extract relatedPort and relatedAddress
|
|
46
|
+
for (let i = 8; i < fields.length; i++) {
|
|
47
|
+
const field = fields[i];
|
|
48
|
+
if (field === 'raddr') {
|
|
49
|
+
this.#relatedAddress = fields[i + 1];
|
|
50
|
+
} else if (field === 'rport') {
|
|
51
|
+
this.#relatedPort = parseInt(fields[i + 1], 10);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (this.#protocol === 'tcp' && field === 'tcptype') {
|
|
55
|
+
this.#tcpType = fields[i + 1] as globalThis.RTCIceTcpCandidateType;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get address(): string | null {
|
|
62
|
+
return this.#address || null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get candidate(): string {
|
|
66
|
+
return this.#candidate;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get component(): globalThis.RTCIceComponent | null {
|
|
70
|
+
return this.#component;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get foundation(): string | null {
|
|
74
|
+
return this.#foundation || null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get port(): number | null {
|
|
78
|
+
return this.#port || null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get priority(): number | null {
|
|
82
|
+
return this.#priority || null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get protocol(): globalThis.RTCIceProtocol | null {
|
|
86
|
+
return this.#protocol || null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get relatedAddress(): string | null {
|
|
90
|
+
return this.#relatedAddress;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get relatedPort(): number | null {
|
|
94
|
+
return this.#relatedPort || null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get sdpMLineIndex(): number | null {
|
|
98
|
+
return this.#sdpMLineIndex;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get sdpMid(): string | null {
|
|
102
|
+
return this.#sdpMid;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get tcpType(): globalThis.RTCIceTcpCandidateType | null {
|
|
106
|
+
return this.#tcpType;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get type(): globalThis.RTCIceCandidateType | null {
|
|
110
|
+
return this.#type || null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get usernameFragment(): string | null {
|
|
114
|
+
return this.#usernameFragment;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
toJSON(): globalThis.RTCIceCandidateInit {
|
|
118
|
+
return {
|
|
119
|
+
candidate: this.#candidate,
|
|
120
|
+
sdpMLineIndex: this.#sdpMLineIndex,
|
|
121
|
+
sdpMid: this.#sdpMid,
|
|
122
|
+
usernameFragment: this.#usernameFragment,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import RTCIceCandidate from './RTCIceCandidate';
|
|
3
|
+
import RTCPeerConnection from './RTCPeerConnection';
|
|
2
4
|
|
|
3
|
-
export default class
|
|
4
|
-
#pc = null;
|
|
5
|
+
export default class RTCIceTransport extends EventTarget implements globalThis.RTCIceTransport {
|
|
6
|
+
#pc: RTCPeerConnection = null;
|
|
5
7
|
#extraFunctions = null;
|
|
6
8
|
|
|
7
|
-
ongatheringstatechange = null;
|
|
8
|
-
onselectedcandidatepairchange = null;
|
|
9
|
-
onstatechange = null;
|
|
9
|
+
ongatheringstatechange: ((this: RTCIceTransport, ev: Event) => any) | null = null;
|
|
10
|
+
onselectedcandidatepairchange: ((this: RTCIceTransport, ev: Event) => any) | null = null;
|
|
11
|
+
onstatechange: ((this: RTCIceTransport, ev: Event) => any) | null = null;
|
|
10
12
|
|
|
11
|
-
constructor({ pc, extraFunctions }) {
|
|
13
|
+
constructor(init: { pc: RTCPeerConnection, extraFunctions }) {
|
|
12
14
|
super();
|
|
13
|
-
this.#pc = pc;
|
|
14
|
-
this.#extraFunctions = extraFunctions;
|
|
15
|
+
this.#pc = init.pc;
|
|
16
|
+
this.#extraFunctions = init.extraFunctions;
|
|
15
17
|
|
|
16
18
|
// forward peerConnection events
|
|
17
19
|
this.#pc.addEventListener('icegatheringstatechange', () => {
|
|
@@ -30,42 +32,42 @@ export default class _RTCIceTransport extends EventTarget {
|
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
get component() {
|
|
34
|
-
|
|
35
|
+
get component(): globalThis.RTCIceComponent {
|
|
36
|
+
const cp = this.getSelectedCandidatePair();
|
|
35
37
|
if (!cp) return null;
|
|
36
38
|
return cp.local.component;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
get gatheringState() {
|
|
41
|
+
get gatheringState(): globalThis.RTCIceGatheringState {
|
|
40
42
|
return this.#pc ? this.#pc.iceGatheringState : 'new';
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
get role() {
|
|
45
|
+
get role(): string {
|
|
44
46
|
return this.#pc.localDescription.type == 'offer' ? 'controlling' : 'controlled';
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
get state() {
|
|
49
|
+
get state(): globalThis.RTCIceTransportState {
|
|
48
50
|
return this.#pc ? this.#pc.iceConnectionState : 'new';
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
getLocalCandidates() {
|
|
53
|
+
getLocalCandidates(): RTCIceCandidate[] {
|
|
52
54
|
return this.#pc ? this.#extraFunctions.localCandidates() : [];
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
getLocalParameters() {
|
|
57
|
+
getLocalParameters(): any {
|
|
56
58
|
/** */
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
getRemoteCandidates() {
|
|
61
|
+
getRemoteCandidates(): RTCIceCandidate[] {
|
|
60
62
|
return this.#pc ? this.#extraFunctions.remoteCandidates() : [];
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
getRemoteParameters() {
|
|
65
|
+
getRemoteParameters(): any {
|
|
64
66
|
/** */
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
getSelectedCandidatePair() {
|
|
68
|
-
|
|
69
|
+
getSelectedCandidatePair(): globalThis.RTCIceCandidatePair | null {
|
|
70
|
+
const cp = this.#extraFunctions.selectedCandidatePair();
|
|
69
71
|
if (!cp) return null;
|
|
70
72
|
return {
|
|
71
73
|
local: new RTCIceCandidate({
|