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.
Files changed (96) hide show
  1. package/.eslintrc.json +25 -25
  2. package/.prettierignore +4 -0
  3. package/.prettierrc +1 -0
  4. package/API.md +4 -4
  5. package/BULDING.md +11 -2
  6. package/CMakeLists.txt +9 -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.map +1 -1
  12. package/dist/cjs/lib/websocket-server.cjs.map +1 -1
  13. package/dist/cjs/lib/websocket.cjs.map +1 -1
  14. package/dist/cjs/polyfill/Events.cjs +52 -3
  15. package/dist/cjs/polyfill/Events.cjs.map +1 -1
  16. package/dist/cjs/polyfill/Exception.cjs.map +1 -1
  17. package/dist/cjs/polyfill/RTCCertificate.cjs +5 -2
  18. package/dist/cjs/polyfill/RTCCertificate.cjs.map +1 -1
  19. package/dist/cjs/polyfill/RTCDataChannel.cjs +27 -19
  20. package/dist/cjs/polyfill/RTCDataChannel.cjs.map +1 -1
  21. package/dist/cjs/polyfill/RTCDtlsTransport.cjs +6 -5
  22. package/dist/cjs/polyfill/RTCDtlsTransport.cjs.map +1 -1
  23. package/dist/cjs/polyfill/RTCError.cjs +9 -2
  24. package/dist/cjs/polyfill/RTCError.cjs.map +1 -1
  25. package/dist/cjs/polyfill/RTCIceCandidate.cjs +13 -8
  26. package/dist/cjs/polyfill/RTCIceCandidate.cjs.map +1 -1
  27. package/dist/cjs/polyfill/RTCIceTransport.cjs +26 -16
  28. package/dist/cjs/polyfill/RTCIceTransport.cjs.map +1 -1
  29. package/dist/cjs/polyfill/RTCPeerConnection.cjs +80 -70
  30. package/dist/cjs/polyfill/RTCPeerConnection.cjs.map +1 -1
  31. package/dist/cjs/polyfill/RTCSctpTransport.cjs +9 -11
  32. package/dist/cjs/polyfill/RTCSctpTransport.cjs.map +1 -1
  33. package/dist/cjs/polyfill/RTCSessionDescription.cjs +10 -2
  34. package/dist/cjs/polyfill/RTCSessionDescription.cjs.map +1 -1
  35. package/dist/cjs/polyfill/index.cjs.map +1 -1
  36. package/dist/esm/index.mjs.map +1 -1
  37. package/dist/esm/lib/datachannel-stream.mjs.map +1 -1
  38. package/dist/esm/lib/index.mjs.map +1 -1
  39. package/dist/esm/lib/websocket-server.mjs.map +1 -1
  40. package/dist/esm/lib/websocket.mjs.map +1 -1
  41. package/dist/esm/polyfill/Events.mjs +52 -4
  42. package/dist/esm/polyfill/Events.mjs.map +1 -1
  43. package/dist/esm/polyfill/Exception.mjs.map +1 -1
  44. package/dist/esm/polyfill/RTCCertificate.mjs +5 -2
  45. package/dist/esm/polyfill/RTCCertificate.mjs.map +1 -1
  46. package/dist/esm/polyfill/RTCDataChannel.mjs +27 -19
  47. package/dist/esm/polyfill/RTCDataChannel.mjs.map +1 -1
  48. package/dist/esm/polyfill/RTCDtlsTransport.mjs +6 -5
  49. package/dist/esm/polyfill/RTCDtlsTransport.mjs.map +1 -1
  50. package/dist/esm/polyfill/RTCError.mjs +9 -2
  51. package/dist/esm/polyfill/RTCError.mjs.map +1 -1
  52. package/dist/esm/polyfill/RTCIceCandidate.mjs +13 -8
  53. package/dist/esm/polyfill/RTCIceCandidate.mjs.map +1 -1
  54. package/dist/esm/polyfill/RTCIceTransport.mjs +26 -17
  55. package/dist/esm/polyfill/RTCIceTransport.mjs.map +1 -1
  56. package/dist/esm/polyfill/RTCPeerConnection.mjs +80 -70
  57. package/dist/esm/polyfill/RTCPeerConnection.mjs.map +1 -1
  58. package/dist/esm/polyfill/RTCSctpTransport.mjs +9 -11
  59. package/dist/esm/polyfill/RTCSctpTransport.mjs.map +1 -1
  60. package/dist/esm/polyfill/RTCSessionDescription.mjs +10 -2
  61. package/dist/esm/polyfill/RTCSessionDescription.mjs.map +1 -1
  62. package/dist/esm/polyfill/index.mjs.map +1 -1
  63. package/dist/types/lib/types.d.ts +6 -6
  64. package/dist/types/polyfill/Events.d.ts +4 -1
  65. package/dist/types/polyfill/RTCCertificate.d.ts +1 -0
  66. package/dist/types/polyfill/RTCDataChannel.d.ts +6 -6
  67. package/dist/types/polyfill/RTCDtlsTransport.d.ts +5 -4
  68. package/dist/types/polyfill/RTCError.d.ts +1 -0
  69. package/dist/types/polyfill/RTCIceCandidate.d.ts +1 -1
  70. package/dist/types/polyfill/RTCIceTransport.d.ts +17 -8
  71. package/dist/types/polyfill/RTCPeerConnection.d.ts +22 -11
  72. package/dist/types/polyfill/RTCSctpTransport.d.ts +4 -3
  73. package/dist/types/polyfill/RTCSessionDescription.d.ts +1 -0
  74. package/jest.config.ts +8 -8
  75. package/package.json +4 -2
  76. package/rollup.config.mjs +1 -1
  77. package/src/cpp/data-channel-wrapper.cpp +11 -0
  78. package/src/index.ts +0 -1
  79. package/src/lib/datachannel-stream.ts +83 -84
  80. package/src/lib/index.ts +163 -140
  81. package/src/lib/types.ts +97 -72
  82. package/src/lib/websocket-server.ts +25 -25
  83. package/src/lib/websocket.ts +19 -19
  84. package/src/polyfill/Events.ts +67 -17
  85. package/src/polyfill/Exception.ts +24 -24
  86. package/src/polyfill/README.md +8 -8
  87. package/src/polyfill/RTCCertificate.ts +16 -12
  88. package/src/polyfill/RTCDataChannel.ts +198 -192
  89. package/src/polyfill/RTCDtlsTransport.ts +39 -39
  90. package/src/polyfill/RTCError.ts +63 -56
  91. package/src/polyfill/RTCIceCandidate.ts +120 -116
  92. package/src/polyfill/RTCIceTransport.ts +72 -64
  93. package/src/polyfill/RTCPeerConnection.ts +436 -420
  94. package/src/polyfill/RTCSctpTransport.ts +44 -47
  95. package/src/polyfill/RTCSessionDescription.ts +26 -17
  96. package/src/polyfill/index.ts +22 -22
@@ -1,54 +1,51 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import RTCDtlsTransport from './RTCDtlsTransport';
3
+ import RTCPeerConnection from './RTCPeerConnection';
3
4
 
4
5
  export default class RTCSctpTransport extends EventTarget implements globalThis.RTCSctpTransport {
5
- #pc: globalThis.RTCPeerConnection = null;
6
- #extraFunctions = null;
7
- #transport: globalThis.RTCDtlsTransport = null;
8
-
9
- onstatechange: ((this: globalThis.RTCSctpTransport, ev: Event) => any) | null = null;
10
-
11
- constructor(initial: { pc: globalThis.RTCPeerConnection, extraFunctions }) {
12
- super();
13
- this.#pc = initial.pc;
14
- this.#extraFunctions = initial.extraFunctions;
15
-
16
- this.#transport = new RTCDtlsTransport({ pc: initial.pc, extraFunctions: initial.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 maxChannels(): number | null {
30
- if (this.state !== 'connected') return null;
31
- return this.#pc ? this.#extraFunctions.maxDataChannelId() : 0;
32
- }
33
-
34
- get maxMessageSize(): number {
35
- if (this.state !== 'connected') return null;
36
- return this.#pc ? this.#extraFunctions.maxMessageSize() : 0;
6
+ #pc: RTCPeerConnection = null;
7
+ #transport: globalThis.RTCDtlsTransport = null;
8
+
9
+ onstatechange: globalThis.RTCSctpTransport['onstatechange'] = null;
10
+
11
+ constructor(initial: { pc: RTCPeerConnection }) {
12
+ super();
13
+ this.#pc = initial.pc;
14
+
15
+ this.#transport = new RTCDtlsTransport({
16
+ pc: initial.pc
17
+ });
18
+
19
+ this.#pc.addEventListener('connectionstatechange', () => {
20
+ const e = new Event('statechange');
21
+ this.dispatchEvent(e);
22
+ this.onstatechange?.(e);
23
+ });
24
+ }
25
+
26
+ get maxChannels(): number | null {
27
+ if (this.state !== 'connected') return null;
28
+ return this.#pc.ext_maxDataChannelId;
29
+ }
30
+
31
+ get maxMessageSize(): number {
32
+ if (this.state !== 'connected') return null;
33
+ return this.#pc?.ext_maxMessageSize ?? 65536;;
34
+ }
35
+
36
+ get state(): globalThis.RTCSctpTransportState {
37
+ // reduce state from new, connecting, connected, disconnected, failed, closed, unknown
38
+ // to RTCSctpTransport states connecting, connected, closed
39
+ let state = this.#pc.connectionState;
40
+ if (state === 'new' || state === 'connecting') {
41
+ state = 'connecting';
42
+ } else if (state === 'disconnected' || state === 'failed' || state === 'closed') {
43
+ state = 'closed';
37
44
  }
45
+ return state;
46
+ }
38
47
 
39
- get state(): globalThis.RTCSctpTransportState {
40
- // reduce state from new, connecting, connected, disconnected, failed, closed, unknown
41
- // to RTCSctpTransport states connecting, connected, closed
42
- let state = this.#pc.connectionState;
43
- if (state === 'new' || state === 'connecting') {
44
- state = 'connecting';
45
- } else if (state === 'disconnected' || state === 'failed' || state === 'closed') {
46
- state = 'closed';
47
- }
48
- return state;
49
- }
50
-
51
- get transport(): globalThis.RTCDtlsTransport {
52
- return this.#transport;
53
- }
48
+ get transport(): globalThis.RTCDtlsTransport {
49
+ return this.#transport;
50
+ }
54
51
  }
@@ -7,26 +7,35 @@
7
7
  // };
8
8
 
9
9
  export default class RTCSessionDescription implements globalThis.RTCSessionDescriptionInit {
10
- #type: globalThis.RTCSdpType;
11
- #sdp: string;
10
+ #type: globalThis.RTCSdpType;
11
+ #sdp: string;
12
12
 
13
- constructor(init: globalThis.RTCSessionDescriptionInit) {
14
- this.#type = init ? init.type : null;
15
- this.#sdp = init ? init.sdp : null;
16
- }
13
+ constructor(init: globalThis.RTCSessionDescriptionInit) {
14
+ this.#type = init?.type;
15
+ this.#sdp = init?.sdp ?? '';
16
+ }
17
17
 
18
- get type(): globalThis.RTCSdpType {
19
- return this.#type;
20
- }
18
+ get type(): globalThis.RTCSdpType {
19
+ return this.#type;
20
+ }
21
21
 
22
- get sdp(): string {
23
- return this.#sdp;
22
+ set type(type) {
23
+ if (type !== 'offer' && type !== 'answer' && type !== 'pranswer' && type !== 'rollback') {
24
+ throw new TypeError(
25
+ `Failed to set the 'type' property on 'RTCSessionDescription': The provided value '${type}' is not a valid enum value of type RTCSdpType.`,
26
+ );
24
27
  }
28
+ this.#type = type;
29
+ }
25
30
 
26
- toJSON(): globalThis.RTCSessionDescriptionInit {
27
- return {
28
- sdp: this.#sdp,
29
- type: this.#type,
30
- };
31
- }
31
+ get sdp(): string {
32
+ return this.#sdp;
33
+ }
34
+
35
+ toJSON(): globalThis.RTCSessionDescriptionInit {
36
+ return {
37
+ sdp: this.#sdp,
38
+ type: this.#type,
39
+ };
40
+ }
32
41
  }
@@ -10,29 +10,29 @@ import { RTCDataChannelEvent, RTCPeerConnectionIceEvent } from './Events';
10
10
  import RTCError from './RTCError';
11
11
 
12
12
  export {
13
- RTCCertificate,
14
- RTCDataChannel,
15
- RTCDtlsTransport,
16
- RTCIceCandidate,
17
- RTCIceTransport,
18
- RTCPeerConnection,
19
- RTCSctpTransport,
20
- RTCSessionDescription,
21
- RTCDataChannelEvent,
22
- RTCPeerConnectionIceEvent,
23
- RTCError,
13
+ RTCCertificate,
14
+ RTCDataChannel,
15
+ RTCDtlsTransport,
16
+ RTCIceCandidate,
17
+ RTCIceTransport,
18
+ RTCPeerConnection,
19
+ RTCSctpTransport,
20
+ RTCSessionDescription,
21
+ RTCDataChannelEvent,
22
+ RTCPeerConnectionIceEvent,
23
+ RTCError,
24
24
  };
25
25
 
26
26
  export default {
27
- RTCCertificate,
28
- RTCDataChannel,
29
- RTCDtlsTransport,
30
- RTCIceCandidate,
31
- RTCIceTransport,
32
- RTCPeerConnection,
33
- RTCSctpTransport,
34
- RTCSessionDescription,
35
- RTCDataChannelEvent,
36
- RTCPeerConnectionIceEvent,
37
- RTCError,
27
+ RTCCertificate,
28
+ RTCDataChannel,
29
+ RTCDtlsTransport,
30
+ RTCIceCandidate,
31
+ RTCIceTransport,
32
+ RTCPeerConnection,
33
+ RTCSctpTransport,
34
+ RTCSessionDescription,
35
+ RTCDataChannelEvent,
36
+ RTCPeerConnectionIceEvent,
37
+ RTCError,
38
38
  };