node-datachannel 0.27.0 → 0.28.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/.eslintrc.json +25 -25
- package/.prettierignore +4 -0
- package/.prettierrc +1 -0
- package/API.md +4 -4
- package/BULDING.md +11 -2
- package/CMakeLists.txt +9 -4
- package/README.md +22 -18
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/datachannel-stream.cjs +13 -13
- package/dist/cjs/lib/datachannel-stream.cjs.map +1 -1
- package/dist/cjs/lib/index.cjs.map +1 -1
- package/dist/cjs/lib/websocket-server.cjs.map +1 -1
- package/dist/cjs/lib/websocket.cjs.map +1 -1
- package/dist/cjs/polyfill/Events.cjs +52 -3
- package/dist/cjs/polyfill/Events.cjs.map +1 -1
- package/dist/cjs/polyfill/Exception.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCCertificate.cjs +5 -2
- package/dist/cjs/polyfill/RTCCertificate.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCDataChannel.cjs +27 -19
- package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs +6 -5
- package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCError.cjs +9 -2
- package/dist/cjs/polyfill/RTCError.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCIceCandidate.cjs +13 -8
- package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCIceTransport.cjs +26 -16
- package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCPeerConnection.cjs +80 -70
- package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCSctpTransport.cjs +9 -11
- package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -1
- package/dist/cjs/polyfill/RTCSessionDescription.cjs +10 -2
- package/dist/cjs/polyfill/RTCSessionDescription.cjs.map +1 -1
- package/dist/cjs/polyfill/index.cjs.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/datachannel-stream.mjs.map +1 -1
- package/dist/esm/lib/index.mjs.map +1 -1
- package/dist/esm/lib/websocket-server.mjs.map +1 -1
- package/dist/esm/lib/websocket.mjs.map +1 -1
- package/dist/esm/polyfill/Events.mjs +52 -4
- package/dist/esm/polyfill/Events.mjs.map +1 -1
- package/dist/esm/polyfill/Exception.mjs.map +1 -1
- package/dist/esm/polyfill/RTCCertificate.mjs +5 -2
- package/dist/esm/polyfill/RTCCertificate.mjs.map +1 -1
- package/dist/esm/polyfill/RTCDataChannel.mjs +27 -19
- package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -1
- package/dist/esm/polyfill/RTCDtlsTransport.mjs +6 -5
- package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -1
- package/dist/esm/polyfill/RTCError.mjs +9 -2
- package/dist/esm/polyfill/RTCError.mjs.map +1 -1
- package/dist/esm/polyfill/RTCIceCandidate.mjs +13 -8
- package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -1
- package/dist/esm/polyfill/RTCIceTransport.mjs +26 -17
- package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -1
- package/dist/esm/polyfill/RTCPeerConnection.mjs +80 -70
- package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
- package/dist/esm/polyfill/RTCSctpTransport.mjs +9 -11
- package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -1
- package/dist/esm/polyfill/RTCSessionDescription.mjs +10 -2
- package/dist/esm/polyfill/RTCSessionDescription.mjs.map +1 -1
- package/dist/esm/polyfill/index.mjs.map +1 -1
- package/dist/types/lib/types.d.ts +6 -6
- package/dist/types/polyfill/Events.d.ts +4 -1
- package/dist/types/polyfill/RTCCertificate.d.ts +1 -0
- package/dist/types/polyfill/RTCDataChannel.d.ts +6 -6
- package/dist/types/polyfill/RTCDtlsTransport.d.ts +5 -4
- package/dist/types/polyfill/RTCError.d.ts +1 -0
- package/dist/types/polyfill/RTCIceCandidate.d.ts +1 -1
- package/dist/types/polyfill/RTCIceTransport.d.ts +17 -8
- package/dist/types/polyfill/RTCPeerConnection.d.ts +22 -11
- package/dist/types/polyfill/RTCSctpTransport.d.ts +4 -3
- package/dist/types/polyfill/RTCSessionDescription.d.ts +1 -0
- package/jest.config.ts +8 -8
- package/package.json +4 -2
- package/rollup.config.mjs +1 -1
- package/src/cpp/data-channel-wrapper.cpp +11 -0
- package/src/index.ts +0 -1
- package/src/lib/datachannel-stream.ts +83 -84
- package/src/lib/index.ts +163 -140
- package/src/lib/types.ts +97 -72
- package/src/lib/websocket-server.ts +25 -25
- package/src/lib/websocket.ts +19 -19
- package/src/polyfill/Events.ts +67 -17
- package/src/polyfill/Exception.ts +24 -24
- package/src/polyfill/README.md +8 -8
- package/src/polyfill/RTCCertificate.ts +16 -12
- package/src/polyfill/RTCDataChannel.ts +198 -192
- package/src/polyfill/RTCDtlsTransport.ts +39 -39
- package/src/polyfill/RTCError.ts +63 -56
- package/src/polyfill/RTCIceCandidate.ts +120 -116
- package/src/polyfill/RTCIceTransport.ts +72 -64
- package/src/polyfill/RTCPeerConnection.ts +436 -420
- package/src/polyfill/RTCSctpTransport.ts +44 -47
- package/src/polyfill/RTCSessionDescription.ts +26 -17
- package/src/polyfill/index.ts +22 -22
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import RTCIceTransport from './RTCIceTransport';
|
|
3
|
+
import RTCPeerConnection from './RTCPeerConnection';
|
|
3
4
|
|
|
4
5
|
export default class RTCDtlsTransport extends EventTarget implements globalThis.RTCDtlsTransport {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
#pc: RTCPeerConnection = null;
|
|
7
|
+
#iceTransport = null;
|
|
8
|
+
|
|
9
|
+
onstatechange: globalThis.RTCDtlsTransport['onstatechange'] = null;
|
|
10
|
+
onerror: globalThis.RTCDtlsTransport['onstatechange'] = null;
|
|
11
|
+
|
|
12
|
+
constructor(init: { pc: RTCPeerConnection }) {
|
|
13
|
+
super();
|
|
14
|
+
this.#pc = init.pc;
|
|
15
|
+
|
|
16
|
+
this.#iceTransport = new RTCIceTransport({
|
|
17
|
+
pc: init.pc
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// forward peerConnection events
|
|
21
|
+
this.#pc.addEventListener('connectionstatechange', () => {
|
|
22
|
+
const e = new Event('statechange');
|
|
23
|
+
this.dispatchEvent(e);
|
|
24
|
+
this.onstatechange?.(e);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get iceTransport(): globalThis.RTCIceTransport {
|
|
29
|
+
return this.#iceTransport;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get state(): globalThis.RTCDtlsTransportState {
|
|
33
|
+
// reduce state from new, connecting, connected, disconnected, failed, closed, unknown
|
|
34
|
+
// to RTCDtlsTRansport states new, connecting, connected, closed, failed
|
|
35
|
+
let state = this.#pc ? this.#pc.connectionState : 'new';
|
|
36
|
+
if (state === 'disconnected') {
|
|
37
|
+
state = 'closed';
|
|
26
38
|
}
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
get state(): globalThis.RTCDtlsTransportState {
|
|
33
|
-
// reduce state from new, connecting, connected, disconnected, failed, closed, unknown
|
|
34
|
-
// to RTCDtlsTRansport states new, connecting, connected, closed, failed
|
|
35
|
-
let state = this.#pc ? this.#pc.connectionState : 'new';
|
|
36
|
-
if (state === 'disconnected') {
|
|
37
|
-
state = 'closed';
|
|
38
|
-
}
|
|
39
|
-
return state;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getRemoteCertificates(): ArrayBuffer[] {
|
|
43
|
-
// TODO: implement
|
|
44
|
-
return [new ArrayBuffer(0)];
|
|
45
|
-
}
|
|
42
|
+
getRemoteCertificates(): ArrayBuffer[] {
|
|
43
|
+
// TODO: implement
|
|
44
|
+
return [new ArrayBuffer(0)];
|
|
45
|
+
}
|
|
46
46
|
}
|
package/src/polyfill/RTCError.ts
CHANGED
|
@@ -1,71 +1,78 @@
|
|
|
1
1
|
export default class RTCError extends DOMException implements globalThis.RTCError {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
#errorDetail: globalThis.RTCErrorDetailType;
|
|
3
|
+
#receivedAlert: number | null;
|
|
4
|
+
#sctpCauseCode: number | null;
|
|
5
|
+
#sdpLineNumber: number | null;
|
|
6
|
+
#sentAlert: number | null;
|
|
7
|
+
#httpRequestStatusCode: number | null;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
constructor(init: globalThis.RTCErrorInit, message?: string) {
|
|
10
|
+
super(message, 'OperationError');
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
if (!init || !init.errorDetail)
|
|
13
|
+
throw new TypeError('Cannot construct RTCError, errorDetail is required');
|
|
14
|
+
if (
|
|
15
|
+
[
|
|
16
|
+
'data-channel-failure',
|
|
17
|
+
'dtls-failure',
|
|
18
|
+
'fingerprint-failure',
|
|
19
|
+
'hardware-encoder-error',
|
|
20
|
+
'hardware-encoder-not-available',
|
|
21
|
+
'sctp-failure',
|
|
22
|
+
'sdp-syntax-error',
|
|
23
|
+
].indexOf(init.errorDetail) === -1
|
|
24
|
+
)
|
|
25
|
+
throw new TypeError('Cannot construct RTCError, errorDetail is invalid');
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
this.#errorDetail = init.errorDetail;
|
|
28
|
+
this.#receivedAlert = init.receivedAlert ?? null;
|
|
29
|
+
this.#sctpCauseCode = init.sctpCauseCode ?? null;
|
|
30
|
+
this.#sdpLineNumber = init.sdpLineNumber ?? null;
|
|
31
|
+
this.#sentAlert = init.sentAlert ?? null;
|
|
32
|
+
this.#httpRequestStatusCode = init.httpRequestStatusCode ?? null;
|
|
33
|
+
}
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
get errorDetail(): globalThis.RTCErrorDetailType {
|
|
36
|
+
return this.#errorDetail;
|
|
37
|
+
}
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
set errorDetail(_value) {
|
|
40
|
+
throw new TypeError('Cannot set errorDetail, it is read-only');
|
|
41
|
+
}
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
get receivedAlert(): number | null {
|
|
44
|
+
return this.#receivedAlert;
|
|
45
|
+
}
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
set receivedAlert(_value) {
|
|
48
|
+
throw new TypeError('Cannot set receivedAlert, it is read-only');
|
|
49
|
+
}
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
get sctpCauseCode(): number | null {
|
|
52
|
+
return this.#sctpCauseCode;
|
|
53
|
+
}
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
set sctpCauseCode(_value) {
|
|
56
|
+
throw new TypeError('Cannot set sctpCauseCode, it is read-only');
|
|
57
|
+
}
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
get httpRequestStatusCode(): number | null {
|
|
60
|
+
return this.#httpRequestStatusCode;
|
|
61
|
+
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
get sdpLineNumber(): number | null {
|
|
64
|
+
return this.#sdpLineNumber;
|
|
65
|
+
}
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
set sdpLineNumber(_value) {
|
|
68
|
+
throw new TypeError('Cannot set sdpLineNumber, it is read-only');
|
|
69
|
+
}
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
get sentAlert(): number | null {
|
|
72
|
+
return this.#sentAlert;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
set sentAlert(_value) {
|
|
76
|
+
throw new TypeError('Cannot set sentAlert, it is read-only');
|
|
77
|
+
}
|
|
71
78
|
}
|
|
@@ -2,123 +2,127 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Example: candidate:123456 1 UDP 123456 192.168.1.1 12345 typ host raddr=10.0.0.1 rport=54321 generation 0
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
export default class RTCIceCandidate implements globalThis.RTCIceCandidate {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
6
|
+
#address: string | null;
|
|
7
|
+
#candidate: string;
|
|
8
|
+
#component: globalThis.RTCIceComponent | null;
|
|
9
|
+
#foundation: string | null;
|
|
10
|
+
#port: number | null;
|
|
11
|
+
#priority: number | null;
|
|
12
|
+
#protocol: globalThis.RTCIceProtocol | null;
|
|
13
|
+
#relatedAddress: string | null;
|
|
14
|
+
#relatedPort: number | null;
|
|
15
|
+
#sdpMLineIndex: number | null;
|
|
16
|
+
#sdpMid: string | null;
|
|
17
|
+
#tcpType: globalThis.RTCIceTcpCandidateType | null;
|
|
18
|
+
#type: globalThis.RTCIceCandidateType | null;
|
|
19
|
+
#usernameFragment: string | null;
|
|
20
|
+
|
|
21
|
+
constructor({
|
|
22
|
+
candidate,
|
|
23
|
+
sdpMLineIndex,
|
|
24
|
+
sdpMid,
|
|
25
|
+
usernameFragment,
|
|
26
|
+
}: globalThis.RTCIceCandidateInit) {
|
|
27
|
+
if (sdpMLineIndex == null && sdpMid == null)
|
|
28
|
+
throw new TypeError('At least one of sdpMLineIndex or sdpMid must be specified');
|
|
29
|
+
|
|
30
|
+
this.#candidate = candidate === null ? 'null' : (candidate ?? '');
|
|
31
|
+
this.#sdpMLineIndex = sdpMLineIndex ?? null;
|
|
32
|
+
this.#sdpMid = sdpMid ?? null;
|
|
33
|
+
this.#usernameFragment = usernameFragment ?? null;
|
|
34
|
+
|
|
35
|
+
if (candidate) {
|
|
36
|
+
const fields = candidate.split(' ');
|
|
37
|
+
this.#foundation = fields[0]!.replace('candidate:', ''); // remove text candidate:
|
|
38
|
+
this.#component = fields[1] == '1' ? 'rtp' : 'rtcp';
|
|
39
|
+
this.#protocol = fields[2] as globalThis.RTCIceProtocol;
|
|
40
|
+
this.#priority = parseInt(fields[3], 10);
|
|
41
|
+
this.#address = fields[4];
|
|
42
|
+
this.#port = parseInt(fields[5], 10);
|
|
43
|
+
this.#type = fields[7] as globalThis.RTCIceCandidateType;
|
|
44
|
+
this.#tcpType = null;
|
|
45
|
+
this.#relatedAddress = null;
|
|
46
|
+
this.#relatedPort = null;
|
|
47
|
+
|
|
48
|
+
// Parse the candidate string to extract relatedPort and relatedAddress
|
|
49
|
+
for (let i = 8; i < fields.length; i++) {
|
|
50
|
+
const field = fields[i];
|
|
51
|
+
if (field === 'raddr') {
|
|
52
|
+
this.#relatedAddress = fields[i + 1];
|
|
53
|
+
} else if (field === 'rport') {
|
|
54
|
+
this.#relatedPort = parseInt(fields[i + 1], 10);
|
|
57
55
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get address(): string | null {
|
|
61
|
-
return this.#address || null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get candidate(): string {
|
|
65
|
-
return this.#candidate;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
get component(): globalThis.RTCIceComponent | null {
|
|
69
|
-
return this.#component;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get foundation(): string | null {
|
|
73
|
-
return this.#foundation || null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get port(): number | null {
|
|
77
|
-
return this.#port || null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
get priority(): number | null {
|
|
81
|
-
return this.#priority || null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get protocol(): globalThis.RTCIceProtocol | null {
|
|
85
|
-
return this.#protocol || null;
|
|
86
|
-
}
|
|
87
56
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
57
|
+
if (this.#protocol === 'tcp' && field === 'tcptype') {
|
|
58
|
+
this.#tcpType = fields[i + 1] as globalThis.RTCIceTcpCandidateType;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get address(): string | null {
|
|
65
|
+
return this.#address ?? null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get candidate(): string {
|
|
69
|
+
return this.#candidate;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get component(): globalThis.RTCIceComponent | null {
|
|
73
|
+
return this.#component;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get foundation(): string | null {
|
|
77
|
+
return this.#foundation ?? null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get port(): number | null {
|
|
81
|
+
return this.#port ?? null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get priority(): number | null {
|
|
85
|
+
return this.#priority ?? null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get protocol(): globalThis.RTCIceProtocol | null {
|
|
89
|
+
return this.#protocol ?? null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get relatedAddress(): string | null {
|
|
93
|
+
return this.#relatedAddress;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get relatedPort(): number | null {
|
|
97
|
+
return this.#relatedPort ?? null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get sdpMLineIndex(): number | null {
|
|
101
|
+
return this.#sdpMLineIndex;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get sdpMid(): string | null {
|
|
105
|
+
return this.#sdpMid;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get tcpType(): globalThis.RTCIceTcpCandidateType | null {
|
|
109
|
+
return this.#tcpType;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get type(): globalThis.RTCIceCandidateType | null {
|
|
113
|
+
return this.#type ?? null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get usernameFragment(): string | null {
|
|
117
|
+
return this.#usernameFragment;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
toJSON(): globalThis.RTCIceCandidateInit {
|
|
121
|
+
return {
|
|
122
|
+
candidate: this.#candidate,
|
|
123
|
+
sdpMLineIndex: this.#sdpMLineIndex,
|
|
124
|
+
sdpMid: this.#sdpMid,
|
|
125
|
+
usernameFragment: this.#usernameFragment,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
124
128
|
}
|
|
@@ -1,82 +1,90 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import RTCIceCandidate from './RTCIceCandidate';
|
|
3
|
+
import RTCPeerConnection from './RTCPeerConnection';
|
|
3
4
|
|
|
4
5
|
export default class RTCIceTransport extends EventTarget implements globalThis.RTCIceTransport {
|
|
5
|
-
|
|
6
|
-
#extraFunctions = null;
|
|
6
|
+
#pc: RTCPeerConnection = null;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
ongatheringstatechange: globalThis.RTCIceTransport['ongatheringstatechange'] = null;
|
|
9
|
+
onselectedcandidatepairchange: globalThis.RTCIceTransport['onselectedcandidatepairchange'] = null;
|
|
10
|
+
onstatechange: globalThis.RTCIceTransport['onstatechange'] = null;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.#extraFunctions = init.extraFunctions;
|
|
12
|
+
constructor(init: { pc: RTCPeerConnection }) {
|
|
13
|
+
super();
|
|
14
|
+
this.#pc = init.pc;
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
this.#pc.addEventListener('icegatheringstatechange', () => {
|
|
17
|
+
const e = new Event('gatheringstatechange');
|
|
18
|
+
this.dispatchEvent(e);
|
|
19
|
+
this.ongatheringstatechange?.(e);
|
|
20
|
+
});
|
|
21
|
+
this.#pc.addEventListener('iceconnectionstatechange', () => {
|
|
22
|
+
const e = new Event('statechange');
|
|
23
|
+
this.dispatchEvent(e);
|
|
24
|
+
this.onstatechange?.(e);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (this.onstatechange) this.onstatechange(e);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
28
|
+
get component(): globalThis.RTCIceComponent {
|
|
29
|
+
const cp = this.getSelectedCandidatePair();
|
|
30
|
+
if (!cp?.local) return null;
|
|
31
|
+
return cp.local.component;
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return cp.local.component;
|
|
38
|
-
}
|
|
34
|
+
get gatheringState(): globalThis.RTCIceGatheringState {
|
|
35
|
+
return this.#pc ? this.#pc.iceGatheringState : 'new';
|
|
36
|
+
}
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
get role(): globalThis.RTCIceRole {
|
|
39
|
+
return this.#pc.localDescription!.type == 'offer' ? 'controlling' : 'controlled';
|
|
40
|
+
}
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
get state(): globalThis.RTCIceTransportState {
|
|
43
|
+
return this.#pc ? this.#pc.iceConnectionState : 'new';
|
|
44
|
+
}
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
getLocalCandidates(): globalThis.RTCIceCandidate[] {
|
|
47
|
+
return this.#pc?.ext_localCandidates ?? [];
|
|
48
|
+
}
|
|
51
49
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
getLocalParameters(): RTCIceParameters | null {
|
|
51
|
+
return new RTCIceParameters(
|
|
52
|
+
new RTCIceCandidate({
|
|
53
|
+
candidate: this.#pc.selectedCandidatePair()!.local.candidate,
|
|
54
|
+
sdpMLineIndex: 0,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
getRemoteCandidates(): globalThis.RTCIceCandidate[] {
|
|
60
|
+
return this.#pc?.ext_remoteCandidates ?? [];
|
|
61
|
+
}
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
getRemoteParameters(): any {
|
|
64
|
+
/** */
|
|
65
|
+
}
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
getSelectedCandidatePair(): globalThis.RTCIceCandidatePair | null {
|
|
68
|
+
const cp = this.#pc?.selectedCandidatePair();
|
|
69
|
+
if (!cp) return null;
|
|
70
|
+
return {
|
|
71
|
+
local: new RTCIceCandidate({
|
|
72
|
+
candidate: cp.local.candidate,
|
|
73
|
+
sdpMid: cp.local.mid,
|
|
74
|
+
}),
|
|
75
|
+
remote: new RTCIceCandidate({
|
|
76
|
+
candidate: cp.remote.candidate,
|
|
77
|
+
sdpMid: cp.remote.mid,
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
67
82
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}),
|
|
76
|
-
remote: new RTCIceCandidate({
|
|
77
|
-
candidate: cp.remote.candidate,
|
|
78
|
-
sdpMid: cp.remote.mid,
|
|
79
|
-
}),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
83
|
+
export class RTCIceParameters implements globalThis.RTCIceParameters {
|
|
84
|
+
usernameFragment = '';
|
|
85
|
+
password = '';
|
|
86
|
+
constructor({ usernameFragment, password = '' }) {
|
|
87
|
+
this.usernameFragment = usernameFragment;
|
|
88
|
+
this.password = password;
|
|
89
|
+
}
|
|
82
90
|
}
|