node-datachannel 0.12.0 → 0.20.0-alpha.2

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 (219) hide show
  1. package/.eslintignore +5 -1
  2. package/.eslintrc.json +27 -0
  3. package/.prettierrc +12 -0
  4. package/CMakeLists.txt +13 -13
  5. package/dist/cjs/index.cjs +11 -0
  6. package/dist/cjs/index.cjs.map +1 -0
  7. package/dist/cjs/lib/datachannel-stream.cjs +101 -0
  8. package/dist/cjs/lib/datachannel-stream.cjs.map +1 -0
  9. package/dist/cjs/lib/index.cjs +61 -0
  10. package/dist/cjs/lib/index.cjs.map +1 -0
  11. package/dist/cjs/lib/node-datachannel.cjs +14 -0
  12. package/dist/cjs/lib/node-datachannel.cjs.map +1 -0
  13. package/dist/cjs/lib/websocket-server.cjs +44 -0
  14. package/dist/cjs/lib/websocket-server.cjs.map +1 -0
  15. package/dist/cjs/lib/websocket.cjs +8 -0
  16. package/dist/cjs/lib/websocket.cjs.map +1 -0
  17. package/dist/cjs/polyfill/Events.cjs +37 -0
  18. package/dist/cjs/polyfill/Events.cjs.map +1 -0
  19. package/dist/cjs/polyfill/Exception.cjs +34 -0
  20. package/dist/cjs/polyfill/Exception.cjs.map +1 -0
  21. package/dist/cjs/polyfill/RTCCertificate.cjs +31 -0
  22. package/dist/cjs/polyfill/RTCCertificate.cjs.map +1 -0
  23. package/dist/cjs/polyfill/RTCDataChannel.cjs +179 -0
  24. package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -0
  25. package/dist/cjs/polyfill/RTCDtlsTransport.cjs +52 -0
  26. package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -0
  27. package/dist/cjs/polyfill/RTCError.cjs +76 -0
  28. package/dist/cjs/polyfill/RTCError.cjs.map +1 -0
  29. package/dist/cjs/polyfill/RTCIceCandidate.cjs +129 -0
  30. package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -0
  31. package/dist/cjs/polyfill/RTCIceTransport.cjs +84 -0
  32. package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -0
  33. package/dist/cjs/polyfill/RTCPeerConnection.cjs +417 -0
  34. package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -0
  35. package/dist/cjs/polyfill/RTCSctpTransport.cjs +61 -0
  36. package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -0
  37. package/dist/cjs/polyfill/RTCSessionDescription.cjs +37 -0
  38. package/dist/cjs/polyfill/RTCSessionDescription.cjs.map +1 -0
  39. package/dist/cjs/polyfill/index.cjs +42 -0
  40. package/dist/cjs/polyfill/index.cjs.map +1 -0
  41. package/dist/esm/index.mjs +8 -0
  42. package/dist/esm/index.mjs.map +1 -0
  43. package/dist/esm/lib/datachannel-stream.mjs +78 -0
  44. package/dist/esm/lib/datachannel-stream.mjs.map +1 -0
  45. package/dist/esm/lib/index.mjs +44 -0
  46. package/dist/esm/lib/index.mjs.map +1 -0
  47. package/dist/esm/lib/node-datachannel.mjs +18 -0
  48. package/dist/esm/lib/node-datachannel.mjs.map +1 -0
  49. package/dist/esm/lib/websocket-server.mjs +42 -0
  50. package/dist/esm/lib/websocket-server.mjs.map +1 -0
  51. package/dist/esm/lib/websocket.mjs +6 -0
  52. package/dist/esm/lib/websocket.mjs.map +1 -0
  53. package/dist/esm/polyfill/Events.mjs +34 -0
  54. package/dist/esm/polyfill/Events.mjs.map +1 -0
  55. package/dist/esm/polyfill/Exception.mjs +28 -0
  56. package/dist/esm/polyfill/Exception.mjs.map +1 -0
  57. package/dist/esm/polyfill/RTCCertificate.mjs +27 -0
  58. package/dist/esm/polyfill/RTCCertificate.mjs.map +1 -0
  59. package/dist/esm/polyfill/RTCDataChannel.mjs +175 -0
  60. package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -0
  61. package/dist/esm/polyfill/RTCDtlsTransport.mjs +48 -0
  62. package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -0
  63. package/dist/esm/polyfill/RTCError.mjs +72 -0
  64. package/dist/esm/polyfill/RTCError.mjs.map +1 -0
  65. package/dist/esm/polyfill/RTCIceCandidate.mjs +125 -0
  66. package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -0
  67. package/dist/esm/polyfill/RTCIceTransport.mjs +80 -0
  68. package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -0
  69. package/dist/esm/polyfill/RTCPeerConnection.mjs +413 -0
  70. package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -0
  71. package/dist/esm/polyfill/RTCSctpTransport.mjs +57 -0
  72. package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -0
  73. package/dist/esm/polyfill/RTCSessionDescription.mjs +33 -0
  74. package/dist/esm/polyfill/RTCSessionDescription.mjs.map +1 -0
  75. package/dist/esm/polyfill/index.mjs +27 -0
  76. package/dist/esm/polyfill/index.mjs.map +1 -0
  77. package/dist/types/lib/datachannel-stream.d.ts +24 -0
  78. package/dist/types/lib/index.d.ts +164 -0
  79. package/dist/types/lib/types.d.ts +106 -0
  80. package/dist/types/lib/websocket-server.d.ts +13 -0
  81. package/dist/types/lib/websocket.d.ts +25 -0
  82. package/dist/types/polyfill/Events.d.ts +15 -0
  83. package/dist/types/polyfill/RTCCertificate.d.ts +8 -0
  84. package/dist/types/polyfill/RTCDataChannel.d.ts +29 -0
  85. package/dist/types/polyfill/RTCDtlsTransport.d.ts +17 -0
  86. package/dist/types/polyfill/RTCError.d.ts +16 -0
  87. package/dist/types/polyfill/RTCIceCandidate.d.ts +21 -0
  88. package/dist/types/polyfill/RTCIceTransport.d.ts +24 -0
  89. package/dist/types/polyfill/RTCPeerConnection.d.ts +56 -0
  90. package/dist/types/polyfill/RTCSctpTransport.d.ts +17 -0
  91. package/dist/types/polyfill/RTCSessionDescription.d.ts +9 -0
  92. package/{polyfill → dist/types/polyfill}/index.d.ts +3 -14
  93. package/jest.config.ts +14 -0
  94. package/package.json +47 -43
  95. package/rollup.config.mjs +63 -0
  96. package/src/index.ts +10 -0
  97. package/{lib/datachannel-stream.js → src/lib/datachannel-stream.ts} +16 -11
  98. package/src/lib/index.ts +180 -0
  99. package/src/lib/node-datachannel.ts +13 -0
  100. package/src/lib/types.ts +126 -0
  101. package/{lib/websocket-server.js → src/lib/websocket-server.ts} +10 -8
  102. package/src/lib/websocket.ts +26 -0
  103. package/src/polyfill/Events.ts +33 -0
  104. package/src/polyfill/Exception.ts +37 -0
  105. package/src/polyfill/RTCCertificate.ts +17 -0
  106. package/{polyfill/RTCDataChannel.js → src/polyfill/RTCDataChannel.ts} +43 -40
  107. package/src/polyfill/RTCDtlsTransport.ts +47 -0
  108. package/src/polyfill/RTCError.ts +71 -0
  109. package/{polyfill/RTCIceCandidate.js → src/polyfill/RTCIceCandidate.ts} +35 -35
  110. package/{polyfill/RTCIceTransport.js → src/polyfill/RTCIceTransport.ts} +22 -20
  111. package/{polyfill/RTCPeerConnection.js → src/polyfill/RTCPeerConnection.ts} +128 -114
  112. package/{polyfill/RTCSctpTransport.js → src/polyfill/RTCSctpTransport.ts} +16 -14
  113. package/{polyfill/RTCSessionDescription.js → src/polyfill/RTCSessionDescription.ts} +7 -12
  114. package/{polyfill/index.js → src/polyfill/index.ts} +10 -10
  115. package/tsconfig.json +20 -13
  116. package/.eslintrc.cjs +0 -8
  117. package/.github/FUNDING.yml +0 -2
  118. package/.github/workflows/build-linux.yml +0 -109
  119. package/.github/workflows/build-mac-m1.yml +0 -38
  120. package/.github/workflows/build-mac-x64.yml +0 -40
  121. package/.github/workflows/build-win.yml +0 -74
  122. package/.github/workflows/lint.yml +0 -20
  123. package/.github/workflows/npm-publish-manual.yml +0 -23
  124. package/.prettierrc.cjs +0 -8
  125. package/build-containers/Dockerfile.alpine +0 -6
  126. package/build-containers/Dockerfile.debian +0 -7
  127. package/cmake/toolchain/ci.cmake +0 -23
  128. package/examples/client-server/README.md +0 -22
  129. package/examples/client-server/client-benchmark.js +0 -230
  130. package/examples/client-server/client-periodic.js +0 -189
  131. package/examples/client-server/client.js +0 -111
  132. package/examples/client-server/package-lock.json +0 -289
  133. package/examples/client-server/package.json +0 -16
  134. package/examples/client-server/signaling-server.js +0 -39
  135. package/examples/electron-demo/README.md +0 -58
  136. package/examples/electron-demo/forge.config.js +0 -49
  137. package/examples/electron-demo/package-lock.json +0 -15877
  138. package/examples/electron-demo/package.json +0 -44
  139. package/examples/electron-demo/src/index.css +0 -7
  140. package/examples/electron-demo/src/index.html +0 -29
  141. package/examples/electron-demo/src/main.js +0 -53
  142. package/examples/electron-demo/src/node-datachannel.js +0 -123
  143. package/examples/electron-demo/src/preload.js +0 -28
  144. package/examples/electron-demo/src/renderer.js +0 -58
  145. package/examples/electron-demo/webpack.main.config.js +0 -21
  146. package/examples/electron-demo/webpack.renderer.config.js +0 -13
  147. package/examples/electron-demo/webpack.rules.js +0 -35
  148. package/examples/media/README.md +0 -34
  149. package/examples/media/main.html +0 -45
  150. package/examples/media/media.js +0 -54
  151. package/examples/simple-peer-usage/main.js +0 -28
  152. package/examples/simple-peer-usage/package-lock.json +0 -317
  153. package/examples/simple-peer-usage/package.json +0 -16
  154. package/examples/websocket/websocket-client.js +0 -20
  155. package/examples/websocket/websocket-server.js +0 -22
  156. package/jest.config.cjs +0 -7
  157. package/lib/index.cjs +0 -194
  158. package/lib/index.d.cts +0 -300
  159. package/lib/index.d.ts +0 -300
  160. package/lib/index.js +0 -58
  161. package/lib/node-datachannel.js +0 -7
  162. package/polyfill/Events.d.ts +0 -9
  163. package/polyfill/Events.js +0 -29
  164. package/polyfill/Exception.js +0 -23
  165. package/polyfill/RTCCertificate.d.ts +0 -7
  166. package/polyfill/RTCCertificate.js +0 -17
  167. package/polyfill/RTCDataChannel.d.ts +0 -35
  168. package/polyfill/RTCDtlsTransport.d.ts +0 -10
  169. package/polyfill/RTCDtlsTransport.js +0 -47
  170. package/polyfill/RTCError.d.ts +0 -11
  171. package/polyfill/RTCError.js +0 -65
  172. package/polyfill/RTCIceCandidate.d.ts +0 -20
  173. package/polyfill/RTCIceTransport.d.ts +0 -18
  174. package/polyfill/RTCPeerConnection.d.ts +0 -62
  175. package/polyfill/RTCSctpTransport.d.ts +0 -10
  176. package/polyfill/RTCSessionDescription.d.ts +0 -8
  177. package/polyfill/index.cjs +0 -1333
  178. package/polyfill/index.d.cts +0 -37
  179. package/test/connectivity.js +0 -86
  180. package/test/jest-tests/basic.test.js +0 -37
  181. package/test/jest-tests/multiple-run.test.js +0 -73
  182. package/test/jest-tests/p2p.test.js +0 -99
  183. package/test/jest-tests/polyfill.test.js +0 -10
  184. package/test/jest-tests/streams.test.js +0 -48
  185. package/test/jest-tests/websocket.test.js +0 -69
  186. package/test/polyfill-connectivity.js +0 -89
  187. package/test/websockets.js +0 -50
  188. package/test/wpt-tests/README.md +0 -46
  189. package/test/wpt-tests/chrome-failed-tests.js +0 -42
  190. package/test/wpt-tests/index.js +0 -96
  191. package/test/wpt-tests/last-test-results.md +0 -301
  192. package/test/wpt-tests/package-lock.json +0 -1712
  193. package/test/wpt-tests/package.json +0 -19
  194. package/test/wpt-tests/wpt-test-list.js +0 -139
  195. package/test/wpt-tests/wpt.js +0 -131
  196. /package/src/{data-channel-wrapper.cpp → cpp/data-channel-wrapper.cpp} +0 -0
  197. /package/src/{data-channel-wrapper.h → cpp/data-channel-wrapper.h} +0 -0
  198. /package/src/{main.cpp → cpp/main.cpp} +0 -0
  199. /package/src/{media-audio-wrapper.cpp → cpp/media-audio-wrapper.cpp} +0 -0
  200. /package/src/{media-audio-wrapper.h → cpp/media-audio-wrapper.h} +0 -0
  201. /package/src/{media-direction.cpp → cpp/media-direction.cpp} +0 -0
  202. /package/src/{media-direction.h → cpp/media-direction.h} +0 -0
  203. /package/src/{media-rtcpreceivingsession-wrapper.cpp → cpp/media-rtcpreceivingsession-wrapper.cpp} +0 -0
  204. /package/src/{media-rtcpreceivingsession-wrapper.h → cpp/media-rtcpreceivingsession-wrapper.h} +0 -0
  205. /package/src/{media-track-wrapper.cpp → cpp/media-track-wrapper.cpp} +0 -0
  206. /package/src/{media-track-wrapper.h → cpp/media-track-wrapper.h} +0 -0
  207. /package/src/{media-video-wrapper.cpp → cpp/media-video-wrapper.cpp} +0 -0
  208. /package/src/{media-video-wrapper.h → cpp/media-video-wrapper.h} +0 -0
  209. /package/src/{peer-connection-wrapper.cpp → cpp/peer-connection-wrapper.cpp} +0 -0
  210. /package/src/{peer-connection-wrapper.h → cpp/peer-connection-wrapper.h} +0 -0
  211. /package/src/{rtc-wrapper.cpp → cpp/rtc-wrapper.cpp} +0 -0
  212. /package/src/{rtc-wrapper.h → cpp/rtc-wrapper.h} +0 -0
  213. /package/src/{thread-safe-callback.cpp → cpp/thread-safe-callback.cpp} +0 -0
  214. /package/src/{thread-safe-callback.h → cpp/thread-safe-callback.h} +0 -0
  215. /package/src/{web-socket-server-wrapper.cpp → cpp/web-socket-server-wrapper.cpp} +0 -0
  216. /package/src/{web-socket-server-wrapper.h → cpp/web-socket-server-wrapper.h} +0 -0
  217. /package/src/{web-socket-wrapper.cpp → cpp/web-socket-wrapper.cpp} +0 -0
  218. /package/src/{web-socket-wrapper.h → cpp/web-socket-wrapper.h} +0 -0
  219. /package/{polyfill → src/polyfill}/README.md +0 -0
@@ -0,0 +1,33 @@
1
+ import RTCDataChannel from './RTCDataChannel';
2
+ import RTCIceCandidate from './RTCIceCandidate';
3
+
4
+
5
+ export class RTCPeerConnectionIceEvent extends Event implements globalThis.RTCPeerConnectionIceEvent {
6
+ #candidate: RTCIceCandidate;
7
+
8
+ constructor(candidate: RTCIceCandidate) {
9
+ super('icecandidate');
10
+
11
+ this.#candidate = candidate;
12
+ }
13
+
14
+ get candidate(): RTCIceCandidate {
15
+ return this.#candidate;
16
+ }
17
+ }
18
+
19
+ export class RTCDataChannelEvent extends Event implements globalThis.RTCDataChannelEvent {
20
+ #channel: RTCDataChannel;
21
+
22
+ constructor(type: string, eventInitDict: globalThis.RTCDataChannelEventInit) {
23
+ super(type);
24
+
25
+ if (type && !eventInitDict.channel) throw new TypeError('channel member is required');
26
+
27
+ this.#channel = eventInitDict?.channel as RTCDataChannel;
28
+ }
29
+
30
+ get channel(): RTCDataChannel {
31
+ return this.#channel;
32
+ }
33
+ }
@@ -0,0 +1,37 @@
1
+ /// <reference lib="dom" />
2
+
3
+ export class InvalidStateError extends DOMException {
4
+ constructor(msg: string) {
5
+ super(msg, 'InvalidStateError');
6
+ }
7
+ };
8
+
9
+ export class TypeError extends DOMException {
10
+ constructor(msg: string) {
11
+ super(msg, 'TypeError');
12
+ }
13
+ };
14
+
15
+ export class OperationError extends DOMException {
16
+ constructor(msg: string) {
17
+ super(msg, 'OperationError');
18
+ }
19
+ };
20
+
21
+ export class NotFoundError extends DOMException {
22
+ constructor(msg: string) {
23
+ super(msg, 'NotFoundError');
24
+ }
25
+ };
26
+
27
+ export class InvalidAccessError extends DOMException {
28
+ constructor(msg: string) {
29
+ super(msg, 'InvalidAccessError');
30
+ }
31
+ };
32
+
33
+ export class SyntaxError extends DOMException {
34
+ constructor(msg: string) {
35
+ super(msg, 'SyntaxError');
36
+ }
37
+ };
@@ -0,0 +1,17 @@
1
+ export default class RTCCertificate implements globalThis.RTCCertificate {
2
+ #expires: number;
3
+ #fingerprints: globalThis.RTCDtlsFingerprint[];
4
+
5
+ constructor() {
6
+ this.#expires = null;
7
+ this.#fingerprints = [];
8
+ }
9
+
10
+ get expires(): number {
11
+ return this.#expires;
12
+ }
13
+
14
+ getFingerprints(): globalThis.RTCDtlsFingerprint[] {
15
+ return this.#fingerprints;
16
+ }
17
+ }
@@ -1,26 +1,29 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import 'node-domexception';
2
- import * as exceptions from './Exception.js';
3
-
4
- export default class _RTCDataChannel extends EventTarget {
5
- #dataChannel;
6
- #readyState;
7
- #bufferedAmountLowThreshold;
8
- #binaryType;
9
- #maxPacketLifeTime;
10
- #maxRetransmits;
11
- #negotiated;
12
- #ordered;
3
+ import * as exceptions from './Exception';
4
+ import { DataChannel } from '../lib/index';
5
+
6
+ export default class RTCDataChannel extends EventTarget implements globalThis.RTCDataChannel {
7
+ #dataChannel: DataChannel;
8
+ #readyState: RTCDataChannelState;
9
+ #bufferedAmountLowThreshold: number;
10
+ #binaryType: BinaryType;
11
+ #maxPacketLifeTime: number | null;
12
+ #maxRetransmits: number | null;
13
+ #negotiated: boolean;
14
+ #ordered: boolean;
13
15
 
14
16
  #closeRequested = false;
15
17
 
16
- onbufferedamountlow;
17
- onclose;
18
- onclosing;
19
- onerror;
20
- onmessage;
21
- onopen;
18
+ // events
19
+ onbufferedamountlow: ((this: RTCDataChannel, ev: Event) => any) | null;
20
+ onclose: ((this: RTCDataChannel, ev: Event) => any) | null;
21
+ onclosing: ((this: RTCDataChannel, ev: Event) => any) | null;
22
+ onerror: ((this: RTCDataChannel, ev: Event) => any) | null;
23
+ onmessage: ((this: RTCDataChannel, ev: MessageEvent) => any) | null;
24
+ onopen: ((this: RTCDataChannel, ev: Event) => any) | null;
22
25
 
23
- constructor(dataChannel, opts = {}) {
26
+ constructor(dataChannel: DataChannel, opts: globalThis.RTCDataChannelInit = {}) {
24
27
  super();
25
28
 
26
29
  this.#dataChannel = dataChannel;
@@ -35,25 +38,25 @@ export default class _RTCDataChannel extends EventTarget {
35
38
  // forward dataChannel events
36
39
  this.#dataChannel.onOpen(() => {
37
40
  this.#readyState = 'open';
38
- this.dispatchEvent(new Event('open', { channel: this }));
41
+ this.dispatchEvent(new Event('open', {}));
39
42
  });
40
43
 
41
44
  this.#dataChannel.onClosed(() => {
42
45
  // Simulate closing event
43
46
  if (!this.#closeRequested) {
44
47
  this.#readyState = 'closing';
45
- this.dispatchEvent(new Event('closing', { channel: this }));
48
+ this.dispatchEvent(new Event('closing'));
46
49
  }
47
50
 
48
51
  setImmediate(() => {
49
52
  this.#readyState = 'closed';
50
- this.dispatchEvent(new Event('close', { channel: this }));
53
+ this.dispatchEvent(new Event('close'));
51
54
  });
52
55
  });
53
56
 
54
57
  this.#dataChannel.onError((msg) => {
55
58
  this.dispatchEvent(
56
- new RTCErrorEvent('error', {
59
+ new globalThis.RTCErrorEvent('error', {
57
60
  error: new RTCError(
58
61
  {
59
62
  errorDetail: 'data-channel-failure',
@@ -65,20 +68,20 @@ export default class _RTCDataChannel extends EventTarget {
65
68
  });
66
69
 
67
70
  this.#dataChannel.onBufferedAmountLow(() => {
68
- this.dispatchEvent(new Event('bufferedamountlow', { channel: this }));
71
+ this.dispatchEvent(new Event('bufferedamountlow'));
69
72
  });
70
73
 
71
74
  this.#dataChannel.onMessage((data) => {
72
75
  if (ArrayBuffer.isView(data)) {
73
- data = data.buffer;
76
+ data = Buffer.from(data.buffer);
74
77
  }
75
78
 
76
- this.dispatchEvent(new MessageEvent('message', { data, channel: this }));
79
+ this.dispatchEvent(new MessageEvent('message', { data }));
77
80
  });
78
81
 
79
82
  // forward events to properties
80
83
  this.addEventListener('message', (e) => {
81
- if (this.onmessage) this.onmessage(e);
84
+ if (this.onmessage) this.onmessage(e as MessageEvent);
82
85
  });
83
86
  this.addEventListener('bufferedamountlow', (e) => {
84
87
  if (this.onbufferedamountlow) this.onbufferedamountlow(e);
@@ -107,15 +110,15 @@ export default class _RTCDataChannel extends EventTarget {
107
110
  this.#binaryType = type;
108
111
  }
109
112
 
110
- get binaryType() {
113
+ get binaryType(): BinaryType {
111
114
  return this.#binaryType;
112
115
  }
113
116
 
114
- get bufferedAmount() {
117
+ get bufferedAmount(): number {
115
118
  return this.#dataChannel.bufferedAmount();
116
119
  }
117
120
 
118
- get bufferedAmountLowThreshold() {
121
+ get bufferedAmountLowThreshold(): number {
119
122
  return this.#bufferedAmountLowThreshold;
120
123
  }
121
124
 
@@ -125,41 +128,41 @@ export default class _RTCDataChannel extends EventTarget {
125
128
  this.#dataChannel.setBufferedAmountLowThreshold(number);
126
129
  }
127
130
 
128
- get id() {
131
+ get id(): number | null {
129
132
  return this.#dataChannel.getId();
130
133
  }
131
134
 
132
- get label() {
135
+ get label(): string {
133
136
  return this.#dataChannel.getLabel();
134
137
  }
135
138
 
136
- get maxPacketLifeTime() {
139
+ get maxPacketLifeTime(): number | null {
137
140
  return this.#maxPacketLifeTime;
138
141
  }
139
142
 
140
- get maxRetransmits() {
143
+ get maxRetransmits(): number | null {
141
144
  return this.#maxRetransmits;
142
145
  }
143
146
 
144
- get negotiated() {
147
+ get negotiated(): boolean {
145
148
  return this.#negotiated;
146
149
  }
147
150
 
148
- get ordered() {
151
+ get ordered(): boolean {
149
152
  return this.#ordered;
150
153
  }
151
154
 
152
- get protocol() {
155
+ get protocol(): string {
153
156
  return this.#dataChannel.getProtocol();
154
157
  }
155
158
 
156
- get readyState() {
159
+ get readyState(): globalThis.RTCDataChannelState {
157
160
  return this.#readyState;
158
161
  }
159
162
 
160
- send(data) {
163
+ send(data): void {
161
164
  if (this.#readyState !== 'open') {
162
- throw exceptions.InvalidStateError(
165
+ throw new exceptions.InvalidStateError(
163
166
  "Failed to execute 'send' on 'RTCDataChannel': RTCDataChannel.readyState is not 'open'",
164
167
  );
165
168
  }
@@ -176,7 +179,7 @@ export default class _RTCDataChannel extends EventTarget {
176
179
  }
177
180
  }
178
181
 
179
- close() {
182
+ close(): void {
180
183
  this.#closeRequested = true;
181
184
  this.#dataChannel.close();
182
185
  }
@@ -0,0 +1,47 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import RTCIceTransport from './RTCIceTransport';
3
+ import RTCPeerConnection from './RTCPeerConnection';
4
+
5
+ export default class RTCDtlsTransport extends EventTarget implements globalThis.RTCDtlsTransport {
6
+ #pc: RTCPeerConnection = null;
7
+ #iceTransport = null;
8
+
9
+ onstatechange: ((this: RTCDtlsTransport, ev: Event) => any) | null = null;
10
+ onerror: ((this: RTCDtlsTransport, ev: Event) => any) | null = null;
11
+
12
+ constructor(init: { pc: RTCPeerConnection, extraFunctions }) {
13
+ super();
14
+ this.#pc = init.pc;
15
+
16
+ this.#iceTransport = new RTCIceTransport({ pc: init.pc, extraFunctions: init.extraFunctions });
17
+
18
+ // forward peerConnection events
19
+ this.#pc.addEventListener('connectionstatechange', () => {
20
+ this.dispatchEvent(new Event('statechange'));
21
+ });
22
+
23
+ // forward events to properties
24
+ this.addEventListener('statechange', (e) => {
25
+ if (this.onstatechange) this.onstatechange(e);
26
+ });
27
+ }
28
+
29
+ get iceTransport(): RTCIceTransport {
30
+ return this.#iceTransport;
31
+ }
32
+
33
+ get state(): RTCDtlsTransportState {
34
+ // reduce state from new, connecting, connected, disconnected, failed, closed, unknown
35
+ // to RTCDtlsTRansport states new, connecting, connected, closed, failed
36
+ let state = this.#pc ? this.#pc.connectionState : 'new';
37
+ if (state === 'disconnected') {
38
+ state = 'closed';
39
+ }
40
+ return state;
41
+ }
42
+
43
+ getRemoteCertificates(): ArrayBuffer[] {
44
+ // TODO: implement
45
+ return [new ArrayBuffer(0)];
46
+ }
47
+ }
@@ -0,0 +1,71 @@
1
+ export default class RTCError extends DOMException implements globalThis.RTCError {
2
+ #errorDetail: RTCErrorDetailType;
3
+ #receivedAlert: number | null;
4
+ #sctpCauseCode: number | null;
5
+ #sdpLineNumber: number | null;
6
+ #sentAlert: number | null;
7
+
8
+ constructor(init: globalThis.RTCErrorInit, message?: string) {
9
+ super(message, 'OperationError');
10
+
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');
24
+
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
+ }
31
+
32
+ get errorDetail(): globalThis.RTCErrorDetailType {
33
+ return this.#errorDetail;
34
+ }
35
+
36
+ set errorDetail(_value) {
37
+ throw new TypeError('Cannot set errorDetail, it is read-only');
38
+ }
39
+
40
+ get receivedAlert(): number | null {
41
+ return this.#receivedAlert;
42
+ }
43
+
44
+ set receivedAlert(_value) {
45
+ throw new TypeError('Cannot set receivedAlert, it is read-only');
46
+ }
47
+
48
+ get sctpCauseCode(): number | null {
49
+ return this.#sctpCauseCode;
50
+ }
51
+
52
+ set sctpCauseCode(_value) {
53
+ throw new TypeError('Cannot set sctpCauseCode, it is read-only');
54
+ }
55
+
56
+ get sdpLineNumber(): number | null {
57
+ return this.#sdpLineNumber;
58
+ }
59
+
60
+ set sdpLineNumber(_value) {
61
+ throw new TypeError('Cannot set sdpLineNumber, it is read-only');
62
+ }
63
+
64
+ get sentAlert(): number | null {
65
+ return this.#sentAlert;
66
+ }
67
+
68
+ set sentAlert(_value) {
69
+ throw new TypeError('Cannot set sentAlert, it is read-only');
70
+ }
71
+ }
@@ -4,23 +4,23 @@
4
4
 
5
5
  import 'node-domexception';
6
6
 
7
- export default class _RTCIceCandidate {
8
- #address;
9
- #candidate;
10
- #component;
11
- #foundation;
12
- #port;
13
- #priority;
14
- #protocol;
15
- #relatedAddress;
16
- #relatedPort;
17
- #sdpMLineIndex;
18
- #sdpMid;
19
- #tcpType;
20
- #type;
21
- #usernameFragment;
22
-
23
- constructor({ candidate, sdpMLineIndex, sdpMid, usernameFragment }) {
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
24
  if (sdpMLineIndex == null && sdpMid == null)
25
25
  throw new TypeError('At least one of sdpMLineIndex or sdpMid must be specified');
26
26
 
@@ -33,11 +33,11 @@ export default class _RTCIceCandidate {
33
33
  const fields = candidate.split(' ');
34
34
  this.#foundation = fields[0].replace('candidate:', ''); // remove text candidate:
35
35
  this.#component = fields[1] == '1' ? 'rtp' : 'rtcp';
36
- this.#protocol = fields[2];
36
+ this.#protocol = fields[2] as globalThis.RTCIceProtocol;
37
37
  this.#priority = parseInt(fields[3], 10);
38
38
  this.#address = fields[4];
39
39
  this.#port = parseInt(fields[5], 10);
40
- this.#type = fields[7];
40
+ this.#type = fields[7] as globalThis.RTCIceCandidateType;
41
41
  this.#tcpType = null;
42
42
  this.#relatedAddress = null;
43
43
  this.#relatedPort = null;
@@ -52,69 +52,69 @@ export default class _RTCIceCandidate {
52
52
  }
53
53
 
54
54
  if (this.#protocol === 'tcp' && field === 'tcptype') {
55
- this.#tcpType = fields[i + 1];
55
+ this.#tcpType = fields[i + 1] as globalThis.RTCIceTcpCandidateType;
56
56
  }
57
57
  }
58
58
  }
59
59
  }
60
60
 
61
- get address() {
61
+ get address(): string | null {
62
62
  return this.#address || null;
63
63
  }
64
64
 
65
- get candidate() {
65
+ get candidate(): string {
66
66
  return this.#candidate;
67
67
  }
68
68
 
69
- get component() {
69
+ get component(): globalThis.RTCIceComponent | null {
70
70
  return this.#component;
71
71
  }
72
72
 
73
- get foundation() {
73
+ get foundation(): string | null {
74
74
  return this.#foundation || null;
75
75
  }
76
76
 
77
- get port() {
77
+ get port(): number | null {
78
78
  return this.#port || null;
79
79
  }
80
80
 
81
- get priority() {
81
+ get priority(): number | null {
82
82
  return this.#priority || null;
83
83
  }
84
84
 
85
- get protocol() {
85
+ get protocol(): globalThis.RTCIceProtocol | null {
86
86
  return this.#protocol || null;
87
87
  }
88
88
 
89
- get relatedAddress() {
89
+ get relatedAddress(): string | null {
90
90
  return this.#relatedAddress;
91
91
  }
92
92
 
93
- get relatedPort() {
93
+ get relatedPort(): number | null {
94
94
  return this.#relatedPort || null;
95
95
  }
96
96
 
97
- get sdpMLineIndex() {
97
+ get sdpMLineIndex(): number | null {
98
98
  return this.#sdpMLineIndex;
99
99
  }
100
100
 
101
- get sdpMid() {
101
+ get sdpMid(): string | null {
102
102
  return this.#sdpMid;
103
103
  }
104
104
 
105
- get tcpType() {
105
+ get tcpType(): globalThis.RTCIceTcpCandidateType | null {
106
106
  return this.#tcpType;
107
107
  }
108
108
 
109
- get type() {
109
+ get type(): globalThis.RTCIceCandidateType | null {
110
110
  return this.#type || null;
111
111
  }
112
112
 
113
- get usernameFragment() {
113
+ get usernameFragment(): string | null {
114
114
  return this.#usernameFragment;
115
115
  }
116
116
 
117
- toJSON() {
117
+ toJSON(): globalThis.RTCIceCandidateInit {
118
118
  return {
119
119
  candidate: this.#candidate,
120
120
  sdpMLineIndex: this.#sdpMLineIndex,
@@ -1,17 +1,19 @@
1
- import RTCIceCandidate from './RTCIceCandidate.js';
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import RTCIceCandidate from './RTCIceCandidate';
3
+ import RTCPeerConnection from './RTCPeerConnection';
2
4
 
3
- export default class _RTCIceTransport extends EventTarget {
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
- let cp = this.getSelectedCandidatePair();
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
- let cp = this.#extraFunctions.selectedCandidatePair();
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({