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
package/src/lib/websocket.ts
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
open(url: string): void;
|
|
6
|
+
forceClose(): void;
|
|
7
|
+
remoteAddress(): string | undefined;
|
|
8
|
+
path(): string | undefined;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
} = nodeDataChannel.WebSocket
|
|
25
|
+
new (config?: WebSocketServerConfiguration): WebSocket;
|
|
26
|
+
} = nodeDataChannel.WebSocket;
|
package/src/polyfill/Events.ts
CHANGED
|
@@ -1,29 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import RTCDataChannel from './RTCDataChannel';
|
|
2
|
+
import RTCError from './RTCError';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export class RTCPeerConnectionIceEvent
|
|
5
|
+
extends Event
|
|
6
|
+
implements globalThis.RTCPeerConnectionIceEvent
|
|
7
|
+
{
|
|
8
|
+
#candidate: globalThis.RTCIceCandidate;
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
constructor(candidate: globalThis.RTCIceCandidate) {
|
|
11
|
+
super('icecandidate');
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
26
|
+
#channel: RTCDataChannel;
|
|
27
|
+
|
|
28
|
+
constructor(type: string = 'datachannel', eventInitDict: globalThis.RTCDataChannelEventInit) {
|
|
29
|
+
super(type);
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
48
|
+
this.#channel = eventInitDict?.channel;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get channel(): RTCDataChannel {
|
|
52
|
+
return this.#channel;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
22
55
|
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
4
|
+
constructor(msg: string) {
|
|
5
|
+
super(msg, 'InvalidStateError');
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
8
|
|
|
9
9
|
export class TypeError extends DOMException {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
10
|
+
constructor(msg: string) {
|
|
11
|
+
super(msg, 'TypeError');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
14
|
|
|
15
15
|
export class OperationError extends DOMException {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
16
|
+
constructor(msg: string) {
|
|
17
|
+
super(msg, 'OperationError');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
export class NotFoundError extends DOMException {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
22
|
+
constructor(msg: string) {
|
|
23
|
+
super(msg, 'NotFoundError');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
26
|
|
|
27
27
|
export class InvalidAccessError extends DOMException {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
28
|
+
constructor(msg: string) {
|
|
29
|
+
super(msg, 'InvalidAccessError');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
32
|
|
|
33
33
|
export class SyntaxError extends DOMException {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
34
|
+
constructor(msg: string) {
|
|
35
|
+
super(msg, 'SyntaxError');
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/polyfill/README.md
CHANGED
|
@@ -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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
3
|
-
|
|
2
|
+
#expires: number = 0;
|
|
3
|
+
#fingerprints: globalThis.RTCDtlsFingerprint[] = [];
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
constructor() {
|
|
6
|
+
this.#expires = null;
|
|
7
|
+
this.#fingerprints = [];
|
|
8
|
+
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
get expires(): number {
|
|
11
|
+
return this.#expires;
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
getFingerprints(): globalThis.RTCDtlsFingerprint[] {
|
|
15
|
+
return this.#fingerprints;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getAlgorithm(): string {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
17
21
|
}
|