node-datachannel 0.26.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.
- package/.eslintrc.json +25 -25
- package/.prettierignore +4 -0
- package/.prettierrc +1 -0
- package/API.md +4 -4
- package/BULDING.md +11 -2
- package/CMakeLists.txt +37 -13
- 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 +1 -3
- 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 +27 -19
- 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 +1 -3
- 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 +27 -19
- 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 +5 -2
- package/dist/types/lib/types.d.ts +6 -6
- package/dist/types/polyfill/Events.d.ts +3 -3
- 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 +4 -6
- 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 +16 -10
- package/dist/types/polyfill/RTCPeerConnection.d.ts +29 -22
- package/dist/types/polyfill/RTCSctpTransport.d.ts +2 -4
- package/dist/types/polyfill/RTCSessionDescription.d.ts +1 -0
- package/jest.config.ts +8 -8
- package/package.json +114 -112
- package/rollup.config.mjs +1 -1
- package/src/cpp/data-channel-wrapper.cpp +11 -0
- package/src/cpp/main.cpp +14 -0
- package/src/cpp/peer-connection-wrapper.cpp +9 -1
- package/src/cpp/peer-connection-wrapper.h +5 -1
- package/src/cpp/rtc-wrapper.cpp +18 -0
- package/src/index.ts +0 -1
- package/src/lib/datachannel-stream.ts +83 -84
- package/src/lib/index.ts +165 -139
- package/src/lib/types.ts +97 -72
- package/src/lib/websocket-server.ts +25 -25
- package/src/lib/websocket.ts +19 -19
- package/src/polyfill/Events.ts +65 -19
- 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 +198 -192
- package/src/polyfill/RTCDtlsTransport.ts +38 -39
- package/src/polyfill/RTCError.ts +63 -56
- package/src/polyfill/RTCIceCandidate.ts +120 -116
- package/src/polyfill/RTCIceTransport.ts +71 -64
- package/src/polyfill/RTCPeerConnection.ts +436 -420
- package/src/polyfill/RTCSctpTransport.ts +43 -47
- package/src/polyfill/RTCSessionDescription.ts +26 -17
- package/src/polyfill/index.ts +22 -22
package/src/lib/index.ts
CHANGED
|
@@ -1,153 +1,180 @@
|
|
|
1
1
|
import nodeDataChannel from './node-datachannel';
|
|
2
2
|
import _DataChannelStream from './datachannel-stream';
|
|
3
3
|
import { WebSocketServer } from './websocket-server';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Channel,
|
|
6
|
+
DataChannelInitConfig,
|
|
7
|
+
DescriptionType,
|
|
8
|
+
Direction,
|
|
9
|
+
LogLevel,
|
|
10
|
+
RtcConfig,
|
|
11
|
+
RTCIceConnectionState,
|
|
12
|
+
RTCIceGatheringState,
|
|
13
|
+
RTCPeerConnectionState,
|
|
14
|
+
RTCSignalingState,
|
|
15
|
+
SctpSettings,
|
|
16
|
+
SelectedCandidateInfo,
|
|
17
|
+
} from './types';
|
|
5
18
|
import { WebSocket } from './websocket';
|
|
6
19
|
|
|
7
|
-
export function preload(): void {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export function
|
|
11
|
-
|
|
20
|
+
export function preload(): void {
|
|
21
|
+
nodeDataChannel.preload();
|
|
22
|
+
}
|
|
23
|
+
export function initLogger(level: LogLevel): void {
|
|
24
|
+
nodeDataChannel.initLogger(level);
|
|
25
|
+
}
|
|
26
|
+
export function cleanup(): void {
|
|
27
|
+
nodeDataChannel.cleanup();
|
|
28
|
+
}
|
|
29
|
+
export function setSctpSettings(settings: SctpSettings): void {
|
|
30
|
+
nodeDataChannel.setSctpSettings(settings);
|
|
31
|
+
}
|
|
32
|
+
export function getLibraryVersion(): string {
|
|
33
|
+
return nodeDataChannel.getLibraryVersion();
|
|
34
|
+
}
|
|
12
35
|
|
|
13
36
|
export interface Audio {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
addAudioCodec(payloadType: number, codec: string, profile?: string): void;
|
|
38
|
+
addOpusCodec(payloadType: number, profile?: string): string;
|
|
39
|
+
direction(): Direction;
|
|
40
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
41
|
+
mid(): string;
|
|
42
|
+
setDirection(dir: Direction): void;
|
|
43
|
+
description(): string;
|
|
44
|
+
removeFormat(fmt: string): void;
|
|
45
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
46
|
+
removeSSRC(ssrc: number): void;
|
|
47
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
48
|
+
hasSSRC(ssrc: number): boolean;
|
|
49
|
+
getSSRCs(): number[];
|
|
50
|
+
getCNameForSsrc(ssrc: number): string;
|
|
51
|
+
setBitrate(bitRate: number): void;
|
|
52
|
+
getBitrate(): number;
|
|
53
|
+
hasPayloadType(payloadType: number): boolean;
|
|
54
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
55
|
+
addRTPMap(): void;
|
|
56
|
+
parseSdpLine(line: string): void;
|
|
34
57
|
}
|
|
35
58
|
export const Audio: {
|
|
36
|
-
|
|
37
|
-
} = nodeDataChannel.Audio
|
|
38
|
-
|
|
59
|
+
new (mid: string, dir: Direction): Audio;
|
|
60
|
+
} = nodeDataChannel.Audio;
|
|
39
61
|
|
|
40
62
|
export interface Video {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
addVideoCodec(payloadType: number, codec: string, profile?: string): void;
|
|
64
|
+
addH264Codec(payloadType: number, profile?: string): void;
|
|
65
|
+
addVP8Codec(payloadType: number): void;
|
|
66
|
+
addVP9Codec(payloadType: number): void;
|
|
67
|
+
direction(): Direction;
|
|
68
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
69
|
+
mid(): string;
|
|
70
|
+
setDirection(dir: Direction): void;
|
|
71
|
+
description(): string;
|
|
72
|
+
removeFormat(fmt: string): void;
|
|
73
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
74
|
+
removeSSRC(ssrc: number): void;
|
|
75
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
76
|
+
hasSSRC(ssrc: number): boolean;
|
|
77
|
+
getSSRCs(): number[];
|
|
78
|
+
getCNameForSsrc(ssrc: number): string;
|
|
79
|
+
setBitrate(bitRate: number): void;
|
|
80
|
+
getBitrate(): number;
|
|
81
|
+
hasPayloadType(payloadType: number): boolean;
|
|
82
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
83
|
+
addRTPMap(): void;
|
|
84
|
+
parseSdpLine(line: string): void;
|
|
63
85
|
}
|
|
64
86
|
export const Video: {
|
|
65
|
-
|
|
66
|
-
} = nodeDataChannel.Video
|
|
87
|
+
new (mid: string, dir: Direction): Video;
|
|
88
|
+
} = nodeDataChannel.Video;
|
|
67
89
|
|
|
68
90
|
export interface Track {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
direction(): Direction;
|
|
92
|
+
mid(): string;
|
|
93
|
+
type(): string;
|
|
94
|
+
close(): void;
|
|
95
|
+
sendMessage(msg: string): boolean;
|
|
96
|
+
sendMessageBinary(buffer: Buffer): boolean;
|
|
97
|
+
isOpen(): boolean;
|
|
98
|
+
isClosed(): boolean;
|
|
99
|
+
bufferedAmount(): number;
|
|
100
|
+
maxMessageSize(): number;
|
|
101
|
+
requestBitrate(bitRate: number): boolean;
|
|
102
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
103
|
+
requestKeyframe(): boolean;
|
|
104
|
+
setMediaHandler(handler: RtcpReceivingSession): void;
|
|
105
|
+
onOpen(cb: () => void): void;
|
|
106
|
+
onClosed(cb: () => void): void;
|
|
107
|
+
onError(cb: (err: string) => void): void;
|
|
108
|
+
onMessage(cb: (msg: Buffer) => void): void;
|
|
87
109
|
}
|
|
88
110
|
export const Track: {
|
|
89
|
-
|
|
90
|
-
} = nodeDataChannel.Track
|
|
111
|
+
new (): Track;
|
|
112
|
+
} = nodeDataChannel.Track;
|
|
91
113
|
|
|
92
114
|
export interface DataChannel extends Channel {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
getLabel(): string;
|
|
116
|
+
getId(): number;
|
|
117
|
+
getProtocol(): string;
|
|
96
118
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
// Channel implementation
|
|
120
|
+
close(): void;
|
|
121
|
+
sendMessage(msg: string): boolean;
|
|
122
|
+
sendMessageBinary(buffer: Buffer | Uint8Array): boolean;
|
|
123
|
+
isOpen(): boolean;
|
|
124
|
+
bufferedAmount(): number;
|
|
125
|
+
maxMessageSize(): number;
|
|
126
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
127
|
+
onOpen(cb: () => void): void;
|
|
128
|
+
onClosed(cb: () => void): void;
|
|
129
|
+
onError(cb: (err: string) => void): void;
|
|
130
|
+
onBufferedAmountLow(cb: () => void): void;
|
|
131
|
+
onMessage(cb: (msg: string | Buffer | ArrayBuffer) => void): void;
|
|
110
132
|
}
|
|
111
133
|
export const DataChannel: {
|
|
112
|
-
|
|
113
|
-
} = nodeDataChannel.DataChannel
|
|
134
|
+
// DataChannel implementation
|
|
135
|
+
} = nodeDataChannel.DataChannel;
|
|
114
136
|
|
|
115
137
|
export interface PeerConnection {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
close(): void;
|
|
139
|
+
setLocalDescription(type?: DescriptionType): void;
|
|
140
|
+
setRemoteDescription(sdp: string, type: DescriptionType): void;
|
|
141
|
+
localDescription(): { type: DescriptionType; sdp: string } | null;
|
|
142
|
+
remoteDescription(): { type: DescriptionType; sdp: string } | null;
|
|
143
|
+
addRemoteCandidate(candidate: string, mid: string): void;
|
|
144
|
+
createDataChannel(label: string, config?: DataChannelInitConfig): DataChannel;
|
|
145
|
+
addTrack(media: Video | Audio): Track;
|
|
146
|
+
hasMedia(): boolean;
|
|
147
|
+
state(): RTCPeerConnectionState;
|
|
148
|
+
iceState(): RTCIceConnectionState;
|
|
149
|
+
signalingState(): RTCSignalingState;
|
|
150
|
+
gatheringState(): RTCIceGatheringState;
|
|
151
|
+
onLocalDescription(cb: (sdp: string, type: DescriptionType) => void): void;
|
|
152
|
+
onLocalCandidate(cb: (candidate: string, mid: string) => void): void;
|
|
153
|
+
onStateChange(cb: (state: string) => void): void;
|
|
154
|
+
onIceStateChange(cb: (state: string) => void): void;
|
|
155
|
+
onSignalingStateChange(cb: (state: string) => void): void;
|
|
156
|
+
onGatheringStateChange(cb: (state: string) => void): void;
|
|
157
|
+
onDataChannel(cb: (dc: DataChannel) => void): void;
|
|
158
|
+
onTrack(cb: (track: Track) => void): void;
|
|
159
|
+
bytesSent(): number;
|
|
160
|
+
bytesReceived(): number;
|
|
161
|
+
rtt(): number;
|
|
162
|
+
getSelectedCandidatePair(): {
|
|
163
|
+
local: SelectedCandidateInfo;
|
|
164
|
+
remote: SelectedCandidateInfo;
|
|
165
|
+
} | null;
|
|
166
|
+
maxDataChannelId(): number;
|
|
167
|
+
maxMessageSize(): number;
|
|
143
168
|
}
|
|
144
169
|
export const PeerConnection: {
|
|
145
|
-
|
|
146
|
-
} = nodeDataChannel.PeerConnection
|
|
170
|
+
new (peerName: string, config: RtcConfig): PeerConnection;
|
|
171
|
+
} = nodeDataChannel.PeerConnection;
|
|
147
172
|
|
|
148
|
-
export
|
|
149
|
-
|
|
150
|
-
|
|
173
|
+
export interface RtcpReceivingSession {}
|
|
174
|
+
|
|
175
|
+
export const RtcpReceivingSession: {
|
|
176
|
+
new (): RtcpReceivingSession;
|
|
177
|
+
} = nodeDataChannel.RtcpReceivingSession;
|
|
151
178
|
|
|
152
179
|
export { WebSocketServer } from './websocket-server';
|
|
153
180
|
export { WebSocket } from './websocket';
|
|
@@ -155,23 +182,22 @@ export { WebSocket } from './websocket';
|
|
|
155
182
|
export const DataChannelStream = _DataChannelStream;
|
|
156
183
|
|
|
157
184
|
export default {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
185
|
+
initLogger,
|
|
186
|
+
cleanup,
|
|
187
|
+
preload,
|
|
188
|
+
setSctpSettings,
|
|
189
|
+
getLibraryVersion,
|
|
190
|
+
RtcpReceivingSession,
|
|
191
|
+
Track,
|
|
192
|
+
Video,
|
|
193
|
+
Audio,
|
|
194
|
+
DataChannel,
|
|
195
|
+
PeerConnection,
|
|
196
|
+
WebSocket,
|
|
197
|
+
WebSocketServer,
|
|
198
|
+
DataChannelStream,
|
|
172
199
|
};
|
|
173
200
|
|
|
174
|
-
|
|
175
201
|
// Types
|
|
176
202
|
// https://github.com/murat-dogan/node-datachannel/issues/300
|
|
177
|
-
export *
|
|
203
|
+
export * from './types';
|
package/src/lib/types.ts
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
export interface Channel {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
close(): void;
|
|
3
|
+
sendMessage(msg: string): boolean;
|
|
4
|
+
sendMessageBinary(buffer: Uint8Array): boolean;
|
|
5
|
+
isOpen(): boolean;
|
|
6
|
+
bufferedAmount(): number;
|
|
7
|
+
maxMessageSize(): number;
|
|
8
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
9
|
+
onOpen(cb: () => void): void;
|
|
10
|
+
onClosed(cb: () => void): void;
|
|
11
|
+
onError(cb: (err: string) => void): void;
|
|
12
|
+
onBufferedAmountLow(cb: () => void): void;
|
|
13
|
+
onMessage(cb: (msg: string | Buffer | ArrayBuffer) => void): void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface WebSocketServerConfiguration {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
port?: number; // default 8080
|
|
18
|
+
enableTls?: boolean; // default = false;
|
|
19
|
+
certificatePemFile?: string;
|
|
20
|
+
keyPemFile?: string;
|
|
21
|
+
keyPemPass?: string;
|
|
22
|
+
bindAddress?: string;
|
|
23
|
+
connectionTimeout?: number; // milliseconds
|
|
24
|
+
maxMessageSize?: number;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// Enum in d.ts is tricky
|
|
@@ -29,83 +29,108 @@ export type LogLevel = 'Verbose' | 'Debug' | 'Info' | 'Warning' | 'Error' | 'Fat
|
|
|
29
29
|
|
|
30
30
|
// SCTP Settings
|
|
31
31
|
export interface SctpSettings {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
recvBufferSize?: number;
|
|
33
|
+
sendBufferSize?: number;
|
|
34
|
+
maxChunksOnQueue?: number;
|
|
35
|
+
initialCongestionWindow?: number;
|
|
36
|
+
congestionControlModule?: number;
|
|
37
|
+
delayedSackTime?: number;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// Proxy Server
|
|
41
41
|
export type ProxyServerType = 'Socks5' | 'Http';
|
|
42
42
|
export interface ProxyServer {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
type: ProxyServerType;
|
|
44
|
+
ip: string;
|
|
45
|
+
port: number;
|
|
46
|
+
username?: string;
|
|
47
|
+
password?: string;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export type RelayType = 'TurnUdp' | 'TurnTcp' | 'TurnTls'
|
|
50
|
+
export type RelayType = 'TurnUdp' | 'TurnTcp' | 'TurnTls';
|
|
51
51
|
|
|
52
52
|
export interface IceServer {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
hostname: string;
|
|
54
|
+
port: number;
|
|
55
|
+
username?: string;
|
|
56
|
+
password?: string;
|
|
57
|
+
relayType?: RelayType;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export type TransportPolicy = 'all' | 'relay';
|
|
61
61
|
|
|
62
62
|
export interface RtcConfig {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
iceServers: (string | IceServer)[];
|
|
64
|
+
proxyServer?: ProxyServer;
|
|
65
|
+
bindAddress?: string;
|
|
66
|
+
enableIceTcp?: boolean;
|
|
67
|
+
enableIceUdpMux?: boolean;
|
|
68
|
+
disableAutoNegotiation?: boolean;
|
|
69
|
+
forceMediaTransport?: boolean;
|
|
70
|
+
portRangeBegin?: number;
|
|
71
|
+
portRangeEnd?: number;
|
|
72
|
+
maxMessageSize?: number;
|
|
73
|
+
mtu?: number;
|
|
74
|
+
iceTransportPolicy?: TransportPolicy;
|
|
75
|
+
disableFingerprintVerification?: boolean;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// Lowercase to match the description type string from libdatachannel
|
|
79
|
-
export type DescriptionType = 'unspec' | 'offer' | 'answer' | 'pranswer' | 'rollback'
|
|
79
|
+
export type DescriptionType = 'unspec' | 'offer' | 'answer' | 'pranswer' | 'rollback';
|
|
80
80
|
|
|
81
81
|
export type RTCSdpType = 'answer' | 'offer' | 'pranswer' | 'rollback';
|
|
82
82
|
|
|
83
|
-
export type RTCIceTransportState =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
export type RTCIceTransportState =
|
|
84
|
+
| 'checking'
|
|
85
|
+
| 'closed'
|
|
86
|
+
| 'completed'
|
|
87
|
+
| 'connected'
|
|
88
|
+
| 'disconnected'
|
|
89
|
+
| 'failed'
|
|
90
|
+
| 'new';
|
|
91
|
+
export type RTCPeerConnectionState =
|
|
92
|
+
| 'closed'
|
|
93
|
+
| 'connected'
|
|
94
|
+
| 'connecting'
|
|
95
|
+
| 'disconnected'
|
|
96
|
+
| 'failed'
|
|
97
|
+
| 'new';
|
|
98
|
+
export type RTCIceConnectionState =
|
|
99
|
+
| 'checking'
|
|
100
|
+
| 'closed'
|
|
101
|
+
| 'completed'
|
|
102
|
+
| 'connected'
|
|
103
|
+
| 'disconnected'
|
|
104
|
+
| 'failed'
|
|
105
|
+
| 'new';
|
|
106
|
+
export type RTCIceGathererState = 'complete' | 'gathering' | 'new';
|
|
107
|
+
export type RTCIceGatheringState = 'complete' | 'gathering' | 'new';
|
|
108
|
+
export type RTCSignalingState =
|
|
109
|
+
| 'closed'
|
|
110
|
+
| 'have-local-offer'
|
|
111
|
+
| 'have-local-pranswer'
|
|
112
|
+
| 'have-remote-offer'
|
|
113
|
+
| 'have-remote-pranswer'
|
|
114
|
+
| 'stable';
|
|
90
115
|
|
|
91
116
|
export interface DataChannelInitConfig {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
117
|
+
protocol?: string;
|
|
118
|
+
negotiated?: boolean;
|
|
119
|
+
id?: number;
|
|
120
|
+
unordered?: boolean; // Reliability
|
|
121
|
+
maxPacketLifeTime?: number; // Reliability
|
|
122
|
+
maxRetransmits?: number; // Reliability
|
|
98
123
|
}
|
|
99
124
|
|
|
100
125
|
export interface SelectedCandidateInfo {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
address: string;
|
|
127
|
+
port: number;
|
|
128
|
+
type: string;
|
|
129
|
+
transportType: string;
|
|
130
|
+
candidate: string;
|
|
131
|
+
mid: string;
|
|
132
|
+
priority: number;
|
|
108
133
|
}
|
|
109
134
|
|
|
110
135
|
// Must be same as rtc enum class Direction
|
|
111
|
-
export type Direction = 'SendOnly' | 'RecvOnly' | 'SendRecv' | 'Inactive' | 'Unknown'
|
|
136
|
+
export type Direction = 'SendOnly' | 'RecvOnly' | 'SendRecv' | 'Inactive' | 'Unknown';
|
|
@@ -4,34 +4,34 @@ import { WebSocketServerConfiguration } from './types';
|
|
|
4
4
|
import { WebSocket } from './websocket';
|
|
5
5
|
|
|
6
6
|
export class WebSocketServer extends EventEmitter {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
|
+
#server: any;
|
|
9
|
+
#clients: WebSocket[] = [];
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
constructor(options: WebSocketServerConfiguration) {
|
|
12
|
+
super();
|
|
13
|
+
this.#server = new nodeDataChannel.WebSocketServer(options);
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
this.#server.onClient((client) => {
|
|
16
|
+
this.emit('client', client);
|
|
17
|
+
this.#clients.push(client);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
port(): number {
|
|
22
|
+
return this.#server?.port() || 0;
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
stop(): void {
|
|
26
|
+
this.#clients.forEach((client) => {
|
|
27
|
+
client?.close();
|
|
28
|
+
});
|
|
29
|
+
this.#server?.stop();
|
|
30
|
+
this.#server = null;
|
|
31
|
+
this.removeAllListeners();
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
onClient(cb: (clientSocket: WebSocket) => void): void {
|
|
35
|
+
if (this.#server) this.on('client', cb);
|
|
36
|
+
}
|
|
37
37
|
}
|
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;
|