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.
Files changed (104) hide show
  1. package/.eslintrc.json +25 -25
  2. package/.prettierignore +7 -0
  3. package/.prettierrc +1 -0
  4. package/API.md +34 -4
  5. package/BULDING.md +12 -2
  6. package/CMakeLists.txt +10 -4
  7. package/README.md +22 -18
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs/lib/datachannel-stream.cjs +13 -13
  10. package/dist/cjs/lib/datachannel-stream.cjs.map +1 -1
  11. package/dist/cjs/lib/index.cjs +4 -1
  12. package/dist/cjs/lib/index.cjs.map +1 -1
  13. package/dist/cjs/lib/websocket-server.cjs.map +1 -1
  14. package/dist/cjs/lib/websocket.cjs.map +1 -1
  15. package/dist/cjs/polyfill/Events.cjs +52 -3
  16. package/dist/cjs/polyfill/Events.cjs.map +1 -1
  17. package/dist/cjs/polyfill/Exception.cjs.map +1 -1
  18. package/dist/cjs/polyfill/RTCCertificate.cjs +5 -2
  19. package/dist/cjs/polyfill/RTCCertificate.cjs.map +1 -1
  20. package/dist/cjs/polyfill/RTCDataChannel.cjs +43 -22
  21. package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -1
  22. package/dist/cjs/polyfill/RTCDtlsTransport.cjs +6 -5
  23. package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -1
  24. package/dist/cjs/polyfill/RTCError.cjs +9 -2
  25. package/dist/cjs/polyfill/RTCError.cjs.map +1 -1
  26. package/dist/cjs/polyfill/RTCIceCandidate.cjs +13 -8
  27. package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -1
  28. package/dist/cjs/polyfill/RTCIceTransport.cjs +26 -16
  29. package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -1
  30. package/dist/cjs/polyfill/RTCPeerConnection.cjs +80 -70
  31. package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
  32. package/dist/cjs/polyfill/RTCSctpTransport.cjs +9 -11
  33. package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -1
  34. package/dist/cjs/polyfill/RTCSessionDescription.cjs +10 -2
  35. package/dist/cjs/polyfill/RTCSessionDescription.cjs.map +1 -1
  36. package/dist/cjs/polyfill/index.cjs.map +1 -1
  37. package/dist/esm/index.mjs.map +1 -1
  38. package/dist/esm/lib/datachannel-stream.mjs.map +1 -1
  39. package/dist/esm/lib/index.mjs +4 -2
  40. package/dist/esm/lib/index.mjs.map +1 -1
  41. package/dist/esm/lib/websocket-server.mjs.map +1 -1
  42. package/dist/esm/lib/websocket.mjs.map +1 -1
  43. package/dist/esm/polyfill/Events.mjs +52 -4
  44. package/dist/esm/polyfill/Events.mjs.map +1 -1
  45. package/dist/esm/polyfill/Exception.mjs.map +1 -1
  46. package/dist/esm/polyfill/RTCCertificate.mjs +5 -2
  47. package/dist/esm/polyfill/RTCCertificate.mjs.map +1 -1
  48. package/dist/esm/polyfill/RTCDataChannel.mjs +43 -22
  49. package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -1
  50. package/dist/esm/polyfill/RTCDtlsTransport.mjs +6 -5
  51. package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -1
  52. package/dist/esm/polyfill/RTCError.mjs +9 -2
  53. package/dist/esm/polyfill/RTCError.mjs.map +1 -1
  54. package/dist/esm/polyfill/RTCIceCandidate.mjs +13 -8
  55. package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -1
  56. package/dist/esm/polyfill/RTCIceTransport.mjs +26 -17
  57. package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -1
  58. package/dist/esm/polyfill/RTCPeerConnection.mjs +80 -70
  59. package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
  60. package/dist/esm/polyfill/RTCSctpTransport.mjs +9 -11
  61. package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -1
  62. package/dist/esm/polyfill/RTCSessionDescription.mjs +10 -2
  63. package/dist/esm/polyfill/RTCSessionDescription.mjs.map +1 -1
  64. package/dist/esm/polyfill/index.mjs.map +1 -1
  65. package/dist/types/lib/index.d.ts +14 -3
  66. package/dist/types/lib/types.d.ts +30 -7
  67. package/dist/types/polyfill/Events.d.ts +4 -1
  68. package/dist/types/polyfill/RTCCertificate.d.ts +1 -0
  69. package/dist/types/polyfill/RTCDataChannel.d.ts +6 -6
  70. package/dist/types/polyfill/RTCDtlsTransport.d.ts +5 -4
  71. package/dist/types/polyfill/RTCError.d.ts +1 -0
  72. package/dist/types/polyfill/RTCIceCandidate.d.ts +1 -1
  73. package/dist/types/polyfill/RTCIceTransport.d.ts +17 -8
  74. package/dist/types/polyfill/RTCPeerConnection.d.ts +22 -11
  75. package/dist/types/polyfill/RTCSctpTransport.d.ts +4 -3
  76. package/dist/types/polyfill/RTCSessionDescription.d.ts +1 -0
  77. package/jest.config.ts +8 -8
  78. package/package.json +6 -3
  79. package/rollup.config.mjs +1 -1
  80. package/src/cpp/data-channel-wrapper.cpp +11 -0
  81. package/src/cpp/ice-udp-mux-listener-wrapper.cpp +150 -0
  82. package/src/cpp/ice-udp-mux-listener-wrapper.h +43 -0
  83. package/src/cpp/main.cpp +2 -0
  84. package/src/cpp/peer-connection-wrapper.cpp +68 -2
  85. package/src/cpp/peer-connection-wrapper.h +1 -0
  86. package/src/index.ts +0 -1
  87. package/src/lib/datachannel-stream.ts +83 -84
  88. package/src/lib/index.ts +175 -139
  89. package/src/lib/types.ts +122 -71
  90. package/src/lib/websocket-server.ts +25 -25
  91. package/src/lib/websocket.ts +19 -19
  92. package/src/polyfill/Events.ts +71 -18
  93. package/src/polyfill/Exception.ts +24 -24
  94. package/src/polyfill/README.md +8 -8
  95. package/src/polyfill/RTCCertificate.ts +16 -12
  96. package/src/polyfill/RTCDataChannel.ts +216 -191
  97. package/src/polyfill/RTCDtlsTransport.ts +39 -39
  98. package/src/polyfill/RTCError.ts +63 -56
  99. package/src/polyfill/RTCIceCandidate.ts +120 -116
  100. package/src/polyfill/RTCIceTransport.ts +72 -64
  101. package/src/polyfill/RTCPeerConnection.ts +436 -420
  102. package/src/polyfill/RTCSctpTransport.ts +44 -47
  103. package/src/polyfill/RTCSessionDescription.ts +26 -17
  104. 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
- #dataChannel: DataChannel;
7
- #readyState: globalThis.RTCDataChannelState;
8
- #bufferedAmountLowThreshold: number;
9
- #binaryType: BinaryType;
10
- #maxPacketLifeTime: number | null;
11
- #maxRetransmits: number | null;
12
- #negotiated: boolean;
13
- #ordered: boolean;
14
-
15
- #closeRequested = false;
16
-
17
- // events
18
- onbufferedamountlow: ((this: globalThis.RTCDataChannel, ev: Event) => any) | null;
19
- onclose: ((this: globalThis.RTCDataChannel, ev: Event) => any) | null;
20
- onclosing: ((this: globalThis.RTCDataChannel, ev: Event) => any) | null;
21
- onerror: ((this: globalThis.RTCDataChannel, ev: Event) => any) | null;
22
- onmessage: ((this: globalThis.RTCDataChannel, ev: MessageEvent) => any) | null;
23
- onopen: ((this: globalThis.RTCDataChannel, ev: Event) => any) | null;
24
-
25
- constructor(dataChannel: DataChannel, opts: globalThis.RTCDataChannelInit = {}) {
26
- super();
27
-
28
- this.#dataChannel = dataChannel;
29
- this.#binaryType = 'blob';
30
- this.#readyState = this.#dataChannel.isOpen() ? 'open' : 'connecting';
31
- this.#bufferedAmountLowThreshold = 0;
32
- this.#maxPacketLifeTime = opts.maxPacketLifeTime || null;
33
- this.#maxRetransmits = opts.maxRetransmits || null;
34
- this.#negotiated = opts.negotiated || false;
35
- this.#ordered = opts.ordered || true;
36
-
37
- // forward dataChannel events
38
- this.#dataChannel.onOpen(() => {
39
- this.#readyState = 'open';
40
- this.dispatchEvent(new Event('open', {}));
41
- });
42
-
43
- this.#dataChannel.onClosed(() => {
44
- // Simulate closing event
45
- if (!this.#closeRequested) {
46
- this.#readyState = 'closing';
47
- this.dispatchEvent(new Event('closing'));
48
- }
49
-
50
- setImmediate(() => {
51
- this.#readyState = 'closed';
52
- this.dispatchEvent(new Event('close'));
53
- });
54
- });
55
-
56
- this.#dataChannel.onError((msg) => {
57
- this.dispatchEvent(
58
- new globalThis.RTCErrorEvent('error', {
59
- error: new RTCError(
60
- {
61
- errorDetail: 'data-channel-failure',
62
- },
63
- msg,
64
- ),
65
- }),
66
- );
67
- });
68
-
69
- this.#dataChannel.onBufferedAmountLow(() => {
70
- this.dispatchEvent(new Event('bufferedamountlow'));
71
- });
72
-
73
- this.#dataChannel.onMessage((data) => {
74
- if (ArrayBuffer.isView(data)) {
75
- if (this.binaryType == 'arraybuffer')
76
- data = data.buffer;
77
- else
78
- data = Buffer.from(data.buffer);
79
- }
80
-
81
- this.dispatchEvent(new MessageEvent('message', { data }));
82
- });
83
-
84
- // forward events to properties
85
- this.addEventListener('message', (e) => {
86
- if (this.onmessage) this.onmessage(e as MessageEvent);
87
- });
88
- this.addEventListener('bufferedamountlow', (e) => {
89
- if (this.onbufferedamountlow) this.onbufferedamountlow(e);
90
- });
91
- this.addEventListener('error', (e) => {
92
- if (this.onerror) this.onerror(e);
93
- });
94
- this.addEventListener('close', (e) => {
95
- if (this.onclose) this.onclose(e);
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
- this.#binaryType = type;
113
- }
114
-
115
- get binaryType(): BinaryType {
116
- return this.#binaryType;
117
- }
118
-
119
- get bufferedAmount(): number {
120
- return this.#dataChannel.bufferedAmount();
121
- }
122
-
123
- get bufferedAmountLowThreshold(): number {
124
- return this.#bufferedAmountLowThreshold;
125
- }
126
-
127
- set bufferedAmountLowThreshold(value) {
128
- const number = Number(value) || 0;
129
- this.#bufferedAmountLowThreshold = number;
130
- this.#dataChannel.setBufferedAmountLowThreshold(number);
131
- }
132
-
133
- get id(): number | null {
134
- return this.#dataChannel.getId();
135
- }
136
-
137
- get label(): string {
138
- return this.#dataChannel.getLabel();
139
- }
140
-
141
- get maxPacketLifeTime(): number | null {
142
- return this.#maxPacketLifeTime;
143
- }
144
-
145
- get maxRetransmits(): number | null {
146
- return this.#maxRetransmits;
147
- }
148
-
149
- get negotiated(): boolean {
150
- return this.#negotiated;
151
- }
152
-
153
- get ordered(): boolean {
154
- return this.#ordered;
155
- }
156
-
157
- get protocol(): string {
158
- return this.#dataChannel.getProtocol();
159
- }
160
-
161
- get readyState(): globalThis.RTCDataChannelState {
162
- return this.#readyState;
163
- }
164
-
165
- send(data): void {
166
- if (this.#readyState !== 'open') {
167
- throw new exceptions.InvalidStateError(
168
- "Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'",
169
- );
170
- }
171
-
172
- // Needs network error, type error implemented
173
- if (typeof data === 'string') {
174
- this.#dataChannel.sendMessage(data);
175
- } else if (data instanceof Blob) {
176
- data.arrayBuffer().then((ab) => {
177
- if (process?.versions?.bun) {
178
- this.#dataChannel.sendMessageBinary(Buffer.from(ab));
179
- } else {
180
- this.#dataChannel.sendMessageBinary(new Uint8Array(ab));
181
- }
182
- });
183
- } else if (data instanceof Uint8Array) {
184
- this.#dataChannel.sendMessageBinary(data);
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
- if (process?.versions?.bun) {
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
- close(): void {
195
- this.#closeRequested = true;
196
- setImmediate(() => {
197
- this.#dataChannel.close();
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
- #pc: globalThis.RTCPeerConnection = null;
6
- #iceTransport = null;
7
-
8
- onstatechange: ((this: globalThis.RTCDtlsTransport, ev: Event) => any) | null = null;
9
- onerror: ((this: globalThis.RTCDtlsTransport, ev: Event) => any) | null = null;
10
-
11
- constructor(init: { pc: globalThis.RTCPeerConnection, extraFunctions }) {
12
- super();
13
- this.#pc = init.pc;
14
-
15
- this.#iceTransport = new RTCIceTransport({ pc: init.pc, extraFunctions: init.extraFunctions });
16
-
17
- // forward peerConnection events
18
- this.#pc.addEventListener('connectionstatechange', () => {
19
- this.dispatchEvent(new Event('statechange'));
20
- });
21
-
22
- // forward events to properties
23
- this.addEventListener('statechange', (e) => {
24
- if (this.onstatechange) this.onstatechange(e);
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
- 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';
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
  }
@@ -1,71 +1,78 @@
1
1
  export default class RTCError extends DOMException implements globalThis.RTCError {
2
- #errorDetail: globalThis.RTCErrorDetailType;
3
- #receivedAlert: number | null;
4
- #sctpCauseCode: number | null;
5
- #sdpLineNumber: number | null;
6
- #sentAlert: number | null;
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
- constructor(init: globalThis.RTCErrorInit, message?: string) {
9
- super(message, 'OperationError');
9
+ constructor(init: globalThis.RTCErrorInit, message?: string) {
10
+ super(message, 'OperationError');
10
11
 
11
- if (!init || !init.errorDetail) throw new TypeError('Cannot construct RTCError, errorDetail is required');
12
- if (
13
- [
14
- 'data-channel-failure',
15
- 'dtls-failure',
16
- 'fingerprint-failure',
17
- 'hardware-encoder-error',
18
- 'hardware-encoder-not-available',
19
- 'sctp-failure',
20
- 'sdp-syntax-error',
21
- ].indexOf(init.errorDetail) === -1
22
- )
23
- throw new TypeError('Cannot construct RTCError, errorDetail is invalid');
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
- this.#errorDetail = init.errorDetail;
26
- this.#receivedAlert = init.receivedAlert ?? null;
27
- this.#sctpCauseCode = init.sctpCauseCode ?? null;
28
- this.#sdpLineNumber = init.sdpLineNumber ?? null;
29
- this.#sentAlert = init.sentAlert ?? null;
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
- get errorDetail(): globalThis.RTCErrorDetailType {
33
- return this.#errorDetail;
34
- }
35
+ get errorDetail(): globalThis.RTCErrorDetailType {
36
+ return this.#errorDetail;
37
+ }
35
38
 
36
- set errorDetail(_value) {
37
- throw new TypeError('Cannot set errorDetail, it is read-only');
38
- }
39
+ set errorDetail(_value) {
40
+ throw new TypeError('Cannot set errorDetail, it is read-only');
41
+ }
39
42
 
40
- get receivedAlert(): number | null {
41
- return this.#receivedAlert;
42
- }
43
+ get receivedAlert(): number | null {
44
+ return this.#receivedAlert;
45
+ }
43
46
 
44
- set receivedAlert(_value) {
45
- throw new TypeError('Cannot set receivedAlert, it is read-only');
46
- }
47
+ set receivedAlert(_value) {
48
+ throw new TypeError('Cannot set receivedAlert, it is read-only');
49
+ }
47
50
 
48
- get sctpCauseCode(): number | null {
49
- return this.#sctpCauseCode;
50
- }
51
+ get sctpCauseCode(): number | null {
52
+ return this.#sctpCauseCode;
53
+ }
51
54
 
52
- set sctpCauseCode(_value) {
53
- throw new TypeError('Cannot set sctpCauseCode, it is read-only');
54
- }
55
+ set sctpCauseCode(_value) {
56
+ throw new TypeError('Cannot set sctpCauseCode, it is read-only');
57
+ }
55
58
 
56
- get sdpLineNumber(): number | null {
57
- return this.#sdpLineNumber;
58
- }
59
+ get httpRequestStatusCode(): number | null {
60
+ return this.#httpRequestStatusCode;
61
+ }
59
62
 
60
- set sdpLineNumber(_value) {
61
- throw new TypeError('Cannot set sdpLineNumber, it is read-only');
62
- }
63
+ get sdpLineNumber(): number | null {
64
+ return this.#sdpLineNumber;
65
+ }
63
66
 
64
- get sentAlert(): number | null {
65
- return this.#sentAlert;
66
- }
67
+ set sdpLineNumber(_value) {
68
+ throw new TypeError('Cannot set sdpLineNumber, it is read-only');
69
+ }
67
70
 
68
- set sentAlert(_value) {
69
- throw new TypeError('Cannot set sentAlert, it is read-only');
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
  }