node-datachannel 0.27.0 → 0.29.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 +7 -0
- package/.prettierrc +1 -0
- package/API.md +34 -4
- package/BULDING.md +12 -2
- package/CMakeLists.txt +10 -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 +4 -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 +43 -22
- 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 +4 -2
- 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 +43 -22
- 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/index.d.ts +14 -3
- package/dist/types/lib/types.d.ts +30 -7
- 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 +6 -3
- package/rollup.config.mjs +1 -1
- package/src/cpp/data-channel-wrapper.cpp +11 -0
- package/src/cpp/ice-udp-mux-listener-wrapper.cpp +150 -0
- package/src/cpp/ice-udp-mux-listener-wrapper.h +43 -0
- package/src/cpp/main.cpp +2 -0
- package/src/cpp/peer-connection-wrapper.cpp +68 -2
- package/src/cpp/peer-connection-wrapper.h +1 -0
- package/src/index.ts +0 -1
- package/src/lib/datachannel-stream.ts +83 -84
- package/src/lib/index.ts +175 -139
- package/src/lib/types.ts +122 -71
- package/src/lib/websocket-server.ts +25 -25
- package/src/lib/websocket.ts +19 -19
- package/src/polyfill/Events.ts +71 -18
- 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 +216 -191
- 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,200 +1,225 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import * as exceptions from './Exception';
|
|
3
3
|
import { DataChannel } from '../lib/index';
|
|
4
|
+
import { RTCErrorEvent } from './Events';
|
|
4
5
|
|
|
5
6
|
export default class RTCDataChannel extends EventTarget implements globalThis.RTCDataChannel {
|
|
6
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.addEventListener('closing', (e) => {
|
|
98
|
-
if (this.onclosing) this.onclosing(e);
|
|
99
|
-
});
|
|
100
|
-
this.addEventListener('open', (e) => {
|
|
101
|
-
if (this.onopen) this.onopen(e);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
set binaryType(type) {
|
|
106
|
-
if (type !== 'blob' && type !== 'arraybuffer') {
|
|
107
|
-
throw new DOMException(
|
|
108
|
-
"Failed to set the 'binaryType' property on 'RTCDataChannel': Unknown binary type : " + type,
|
|
109
|
-
'TypeMismatchError',
|
|
110
|
-
);
|
|
7
|
+
#dataChannel: DataChannel;
|
|
8
|
+
#readyState: globalThis.RTCDataChannelState;
|
|
9
|
+
#bufferedAmountLowThreshold: number;
|
|
10
|
+
#binaryType: BinaryType;
|
|
11
|
+
#maxPacketLifeTime: number | null;
|
|
12
|
+
#maxRetransmits: number | null;
|
|
13
|
+
#negotiated: boolean;
|
|
14
|
+
#ordered: boolean;
|
|
15
|
+
#id: number;
|
|
16
|
+
#label: string;
|
|
17
|
+
#protocol: string;
|
|
18
|
+
|
|
19
|
+
#closeRequested = false;
|
|
20
|
+
|
|
21
|
+
// events
|
|
22
|
+
onbufferedamountlow: globalThis.RTCDataChannel['onbufferedamountlow'] = null;
|
|
23
|
+
onclose: globalThis.RTCDataChannel['onclose'] = null;
|
|
24
|
+
onclosing: globalThis.RTCDataChannel['onclosing'] = null;
|
|
25
|
+
onerror: globalThis.RTCDataChannel['onerror'] = null;
|
|
26
|
+
onmessage: globalThis.RTCDataChannel['onmessage'] = null;
|
|
27
|
+
onopen: globalThis.RTCDataChannel['onopen'] = null;
|
|
28
|
+
|
|
29
|
+
constructor(dataChannel: DataChannel, opts: globalThis.RTCDataChannelInit = {}) {
|
|
30
|
+
super();
|
|
31
|
+
|
|
32
|
+
this.#dataChannel = dataChannel;
|
|
33
|
+
this.#binaryType = 'arraybuffer';
|
|
34
|
+
this.#readyState = this.#dataChannel.isOpen() ? 'open' : 'connecting';
|
|
35
|
+
this.#bufferedAmountLowThreshold = 0;
|
|
36
|
+
this.#maxPacketLifeTime = opts.maxPacketLifeTime ?? null;
|
|
37
|
+
this.#maxRetransmits = opts.maxRetransmits ?? null;
|
|
38
|
+
this.#negotiated = opts.negotiated ?? false;
|
|
39
|
+
this.#ordered = opts.ordered ?? true;
|
|
40
|
+
this.#id = this.#dataChannel.getId();
|
|
41
|
+
this.#label = this.#dataChannel.getLabel();
|
|
42
|
+
this.#protocol = this.#dataChannel.getProtocol();
|
|
43
|
+
|
|
44
|
+
// forward dataChannel events
|
|
45
|
+
this.#dataChannel.onOpen(() => {
|
|
46
|
+
this.#readyState = 'open';
|
|
47
|
+
this.dispatchEvent(new Event('open', {}));
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
this.#dataChannel.onClosed(() => {
|
|
51
|
+
// Simulate closing event
|
|
52
|
+
if (!this.#closeRequested) {
|
|
53
|
+
this.#readyState = 'closing';
|
|
54
|
+
this.dispatchEvent(new Event('closing'));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
setImmediate(() => {
|
|
58
|
+
this.#readyState = 'closed';
|
|
59
|
+
this.dispatchEvent(new Event('close'));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
this.#dataChannel.onError((msg) => {
|
|
64
|
+
this.dispatchEvent(
|
|
65
|
+
new RTCErrorEvent('error', {
|
|
66
|
+
error: new RTCError(
|
|
67
|
+
{
|
|
68
|
+
errorDetail: 'data-channel-failure',
|
|
69
|
+
},
|
|
70
|
+
msg,
|
|
71
|
+
),
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.#dataChannel.onBufferedAmountLow(() => {
|
|
77
|
+
this.dispatchEvent(new Event('bufferedamountlow'));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
this.#dataChannel.onMessage((message) => {
|
|
81
|
+
if (typeof message === 'string') {
|
|
82
|
+
this.dispatchEvent(new MessageEvent('message', { data: message }));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let data: Blob | ArrayBuffer;
|
|
87
|
+
|
|
88
|
+
if (message instanceof ArrayBuffer) {
|
|
89
|
+
data = message;
|
|
90
|
+
} else {
|
|
91
|
+
data = message.buffer;
|
|
92
|
+
|
|
93
|
+
if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {
|
|
94
|
+
// message is view on underlying buffer, must create new
|
|
95
|
+
// ArrayBuffer that only contains message data
|
|
96
|
+
data = new ArrayBuffer(message.byteLength);
|
|
97
|
+
new Uint8Array(data, 0, message.byteLength).set(message);
|
|
111
98
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (this.#binaryType === 'blob') {
|
|
102
|
+
data = new Blob([data]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.dispatchEvent(new MessageEvent('message', { data }));
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// forward events to properties
|
|
109
|
+
this.addEventListener('message', (e) => {
|
|
110
|
+
if (this.onmessage) this.onmessage(e as MessageEvent);
|
|
111
|
+
});
|
|
112
|
+
this.addEventListener('bufferedamountlow', (e) => {
|
|
113
|
+
if (this.onbufferedamountlow) this.onbufferedamountlow(e);
|
|
114
|
+
});
|
|
115
|
+
this.addEventListener('error', (e) => {
|
|
116
|
+
if (this.onerror) this.onerror(e as RTCErrorEvent);
|
|
117
|
+
});
|
|
118
|
+
this.addEventListener('close', (e) => {
|
|
119
|
+
if (this.onclose) this.onclose(e);
|
|
120
|
+
});
|
|
121
|
+
this.addEventListener('closing', (e) => {
|
|
122
|
+
if (this.onclosing) this.onclosing(e);
|
|
123
|
+
});
|
|
124
|
+
this.addEventListener('open', (e) => {
|
|
125
|
+
if (this.onopen) this.onopen(e);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
set binaryType(type) {
|
|
130
|
+
if (type !== 'blob' && type !== 'arraybuffer') {
|
|
131
|
+
throw new DOMException(
|
|
132
|
+
"Failed to set the 'binaryType' property on 'RTCDataChannel': Unknown binary type : " +
|
|
133
|
+
type,
|
|
134
|
+
'TypeMismatchError',
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
this.#binaryType = type;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
get binaryType(): BinaryType {
|
|
141
|
+
return this.#binaryType;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
get bufferedAmount(): number {
|
|
145
|
+
return this.#dataChannel.bufferedAmount();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get bufferedAmountLowThreshold(): number {
|
|
149
|
+
return this.#bufferedAmountLowThreshold;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
set bufferedAmountLowThreshold(value) {
|
|
153
|
+
const number = Number(value) || 0;
|
|
154
|
+
this.#bufferedAmountLowThreshold = number;
|
|
155
|
+
this.#dataChannel.setBufferedAmountLowThreshold(number);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
get id(): number | null {
|
|
159
|
+
return this.#id;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
get label(): string {
|
|
163
|
+
return this.#label;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get maxPacketLifeTime(): number | null {
|
|
167
|
+
return this.#maxPacketLifeTime;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get maxRetransmits(): number | null {
|
|
171
|
+
return this.#maxRetransmits;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
get negotiated(): boolean {
|
|
175
|
+
return this.#negotiated;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get ordered(): boolean {
|
|
179
|
+
return this.#ordered;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
get protocol(): string {
|
|
183
|
+
return this.#protocol;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
get readyState(): globalThis.RTCDataChannelState {
|
|
187
|
+
return this.#readyState;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
send(data): void {
|
|
191
|
+
if (this.#readyState !== 'open') {
|
|
192
|
+
throw new exceptions.InvalidStateError(
|
|
193
|
+
"Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'",
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Needs network error, type error implemented
|
|
198
|
+
if (typeof data === 'string') {
|
|
199
|
+
this.#dataChannel.sendMessage(data);
|
|
200
|
+
} else if (data instanceof Blob) {
|
|
201
|
+
data.arrayBuffer().then((ab) => {
|
|
202
|
+
if (process?.versions?.bun) {
|
|
203
|
+
this.#dataChannel.sendMessageBinary(Buffer.from(ab));
|
|
185
204
|
} else {
|
|
186
|
-
|
|
187
|
-
this.#dataChannel.sendMessageBinary(Buffer.from(data));
|
|
188
|
-
} else {
|
|
189
|
-
this.#dataChannel.sendMessageBinary(new Uint8Array(data));
|
|
190
|
-
}
|
|
205
|
+
this.#dataChannel.sendMessageBinary(new Uint8Array(ab));
|
|
191
206
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
207
|
+
});
|
|
208
|
+
} else if (data instanceof Uint8Array) {
|
|
209
|
+
this.#dataChannel.sendMessageBinary(data);
|
|
210
|
+
} else {
|
|
211
|
+
if (process?.versions?.bun) {
|
|
212
|
+
this.#dataChannel.sendMessageBinary(Buffer.from(data));
|
|
213
|
+
} else {
|
|
214
|
+
this.#dataChannel.sendMessageBinary(new Uint8Array(data));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
close(): void {
|
|
220
|
+
this.#closeRequested = true;
|
|
221
|
+
setImmediate(() => {
|
|
222
|
+
this.#dataChannel.close();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
200
225
|
}
|
|
@@ -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
|
}
|