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
@@ -2,25 +2,25 @@ import nodeDataChannel from './node-datachannel';
2
2
  import { Channel, WebSocketServerConfiguration } from './types';
3
3
 
4
4
  export interface WebSocket extends Channel {
5
- open(url: string): void;
6
- forceClose(): void;
7
- remoteAddress(): string | undefined;
8
- path(): string | undefined;
5
+ open(url: string): void;
6
+ forceClose(): void;
7
+ remoteAddress(): string | undefined;
8
+ path(): string | undefined;
9
9
 
10
- // Channel implementation
11
- close(): void;
12
- sendMessage(msg: string): boolean;
13
- sendMessageBinary(buffer: Uint8Array): boolean;
14
- isOpen(): boolean;
15
- bufferedAmount(): number;
16
- maxMessageSize(): number;
17
- setBufferedAmountLowThreshold(newSize: number): void;
18
- onOpen(cb: () => void): void;
19
- onClosed(cb: () => void): void;
20
- onError(cb: (err: string) => void): void;
21
- onBufferedAmountLow(cb: () => void): void;
22
- onMessage(cb: (msg: string | Buffer) => void): void;
10
+ // Channel implementation
11
+ close(): void;
12
+ sendMessage(msg: string): boolean;
13
+ sendMessageBinary(buffer: Uint8Array): boolean;
14
+ isOpen(): boolean;
15
+ bufferedAmount(): number;
16
+ maxMessageSize(): number;
17
+ setBufferedAmountLowThreshold(newSize: number): void;
18
+ onOpen(cb: () => void): void;
19
+ onClosed(cb: () => void): void;
20
+ onError(cb: (err: string) => void): void;
21
+ onBufferedAmountLow(cb: () => void): void;
22
+ onMessage(cb: (msg: string | Buffer) => void): void;
23
23
  }
24
24
  export const WebSocket: {
25
- new(config?: WebSocketServerConfiguration): WebSocket
26
- } = nodeDataChannel.WebSocket
25
+ new (config?: WebSocketServerConfiguration): WebSocket;
26
+ } = nodeDataChannel.WebSocket;
@@ -1,29 +1,82 @@
1
- export class RTCPeerConnectionIceEvent extends Event implements globalThis.RTCPeerConnectionIceEvent {
2
- #candidate: globalThis.RTCIceCandidate;
1
+ import RTCDataChannel from './RTCDataChannel';
2
+ import RTCError from './RTCError';
3
3
 
4
- constructor(candidate: globalThis.RTCIceCandidate) {
5
- super('icecandidate');
4
+ export class RTCPeerConnectionIceEvent
5
+ extends Event
6
+ implements globalThis.RTCPeerConnectionIceEvent
7
+ {
8
+ #candidate: globalThis.RTCIceCandidate;
6
9
 
7
- this.#candidate = candidate;
8
- }
10
+ constructor(candidate: globalThis.RTCIceCandidate) {
11
+ super('icecandidate');
9
12
 
10
- get candidate(): globalThis.RTCIceCandidate {
11
- return this.#candidate;
12
- }
13
+ this.#candidate = candidate;
14
+ }
15
+
16
+ get candidate(): globalThis.RTCIceCandidate {
17
+ return this.#candidate;
18
+ }
19
+
20
+ get url(): string {
21
+ return '';
22
+ }
13
23
  }
14
24
 
15
25
  export class RTCDataChannelEvent extends Event implements globalThis.RTCDataChannelEvent {
16
- #channel: globalThis.RTCDataChannel;
26
+ #channel: RTCDataChannel;
27
+
28
+ constructor(type: string = 'datachannel', eventInitDict: globalThis.RTCDataChannelEventInit) {
29
+ super(type);
17
30
 
18
- constructor(type: string, eventInitDict: globalThis.RTCDataChannelEventInit) {
19
- super(type);
31
+ if (arguments.length === 0)
32
+ throw new TypeError(
33
+ `Failed to construct 'RTCDataChannelEvent': 2 arguments required, but only ${arguments.length} present.`,
34
+ );
35
+ if (typeof eventInitDict !== 'object')
36
+ throw new TypeError(
37
+ "Failed to construct 'RTCDataChannelEvent': The provided value is not of type 'RTCDataChannelEventInit'.",
38
+ );
39
+ if (!eventInitDict.channel)
40
+ throw new TypeError(
41
+ "Failed to construct 'RTCDataChannelEvent': Failed to read the 'channel' property from 'RTCDataChannelEventInit': Required member is undefined.",
42
+ );
43
+ if (eventInitDict.channel.constructor !== RTCDataChannel)
44
+ throw new TypeError(
45
+ "Failed to construct 'RTCDataChannelEvent': Failed to read the 'channel' property from 'RTCDataChannelEventInit': Failed to convert value to 'RTCDataChannel'.",
46
+ );
20
47
 
21
- if (type && !eventInitDict.channel) throw new TypeError('channel member is required');
48
+ this.#channel = eventInitDict?.channel;
49
+ }
50
+
51
+ get channel(): RTCDataChannel {
52
+ return this.#channel;
53
+ }
54
+ }
22
55
 
23
- this.#channel = eventInitDict?.channel as globalThis.RTCDataChannel;
24
- }
56
+ export class RTCErrorEvent extends Event implements globalThis.RTCErrorEvent {
57
+ #error: RTCError;
58
+ constructor(type: string, init: globalThis.RTCErrorEventInit) {
59
+ if (arguments.length < 2)
60
+ throw new TypeError(
61
+ `Failed to construct 'RTCErrorEvent': 2 arguments required, but only ${arguments.length} present.`,
62
+ );
63
+ if (typeof init !== 'object')
64
+ throw new TypeError(
65
+ "Failed to construct 'RTCErrorEvent': The provided value is not of type 'RTCErrorEventInit'.",
66
+ );
67
+ if (!init.error)
68
+ throw new TypeError(
69
+ "Failed to construct 'RTCErrorEvent': Failed to read the 'error' property from 'RTCErrorEventInit': Required member is undefined.",
70
+ );
71
+ if (init.error.constructor !== RTCError)
72
+ throw new TypeError(
73
+ "Failed to construct 'RTCErrorEvent': Failed to read the 'error' property from 'RTCErrorEventInit': Failed to convert value to 'RTCError'.",
74
+ );
75
+ super(type || 'error');
76
+ this.#error = init.error;
77
+ }
25
78
 
26
- get channel(): globalThis.RTCDataChannel {
27
- return this.#channel;
28
- }
79
+ get error(): RTCError {
80
+ return this.#error;
81
+ }
29
82
  }
@@ -1,37 +1,37 @@
1
1
  /// <reference lib="dom" />
2
2
 
3
3
  export class InvalidStateError extends DOMException {
4
- constructor(msg: string) {
5
- super(msg, 'InvalidStateError');
6
- }
7
- };
4
+ constructor(msg: string) {
5
+ super(msg, 'InvalidStateError');
6
+ }
7
+ }
8
8
 
9
9
  export class TypeError extends DOMException {
10
- constructor(msg: string) {
11
- super(msg, 'TypeError');
12
- }
13
- };
10
+ constructor(msg: string) {
11
+ super(msg, 'TypeError');
12
+ }
13
+ }
14
14
 
15
15
  export class OperationError extends DOMException {
16
- constructor(msg: string) {
17
- super(msg, 'OperationError');
18
- }
19
- };
16
+ constructor(msg: string) {
17
+ super(msg, 'OperationError');
18
+ }
19
+ }
20
20
 
21
21
  export class NotFoundError extends DOMException {
22
- constructor(msg: string) {
23
- super(msg, 'NotFoundError');
24
- }
25
- };
22
+ constructor(msg: string) {
23
+ super(msg, 'NotFoundError');
24
+ }
25
+ }
26
26
 
27
27
  export class InvalidAccessError extends DOMException {
28
- constructor(msg: string) {
29
- super(msg, 'InvalidAccessError');
30
- }
31
- };
28
+ constructor(msg: string) {
29
+ super(msg, 'InvalidAccessError');
30
+ }
31
+ }
32
32
 
33
33
  export class SyntaxError extends DOMException {
34
- constructor(msg: string) {
35
- super(msg, 'SyntaxError');
36
- }
37
- };
34
+ constructor(msg: string) {
35
+ super(msg, 'SyntaxError');
36
+ }
37
+ }
@@ -20,22 +20,22 @@ var peer1 = new Peer({ initiator: true, wrtc: nodeDatachannelPolyfill });
20
20
  var peer2 = new Peer({ wrtc: nodeDatachannelPolyfill });
21
21
 
22
22
  peer1.on('signal', (data) => {
23
- // when peer1 has signaling data, give it to peer2 somehow
24
- peer2.signal(data);
23
+ // when peer1 has signaling data, give it to peer2 somehow
24
+ peer2.signal(data);
25
25
  });
26
26
 
27
27
  peer2.on('signal', (data) => {
28
- // when peer2 has signaling data, give it to peer1 somehow
29
- peer1.signal(data);
28
+ // when peer2 has signaling data, give it to peer1 somehow
29
+ peer1.signal(data);
30
30
  });
31
31
 
32
32
  peer1.on('connect', () => {
33
- // wait for 'connect' event before using the data channel
34
- peer1.send('hey peer2, how is it going?');
33
+ // wait for 'connect' event before using the data channel
34
+ peer1.send('hey peer2, how is it going?');
35
35
  });
36
36
 
37
37
  peer2.on('data', (data) => {
38
- // got a data channel message
39
- console.log('got a message from peer1: ' + data);
38
+ // got a data channel message
39
+ console.log('got a message from peer1: ' + data);
40
40
  });
41
41
  ```
@@ -1,17 +1,21 @@
1
1
  export default class RTCCertificate implements globalThis.RTCCertificate {
2
- #expires: number;
3
- #fingerprints: globalThis.RTCDtlsFingerprint[];
2
+ #expires: number = 0;
3
+ #fingerprints: globalThis.RTCDtlsFingerprint[] = [];
4
4
 
5
- constructor() {
6
- this.#expires = null;
7
- this.#fingerprints = [];
8
- }
5
+ constructor() {
6
+ this.#expires = null;
7
+ this.#fingerprints = [];
8
+ }
9
9
 
10
- get expires(): number {
11
- return this.#expires;
12
- }
10
+ get expires(): number {
11
+ return this.#expires;
12
+ }
13
13
 
14
- getFingerprints(): globalThis.RTCDtlsFingerprint[] {
15
- return this.#fingerprints;
16
- }
14
+ getFingerprints(): globalThis.RTCDtlsFingerprint[] {
15
+ return this.#fingerprints;
16
+ }
17
+
18
+ getAlgorithm(): string {
19
+ return '';
20
+ }
17
21
  }