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/index.ts
CHANGED
|
@@ -1,156 +1,192 @@
|
|
|
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';
|
|
19
|
+
import type { CertificateFingerprint, IceUdpMuxRequest, LocalDescriptionInit } from './types';
|
|
6
20
|
|
|
7
|
-
export function preload(): void {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export function
|
|
11
|
-
|
|
21
|
+
export function preload(): void {
|
|
22
|
+
nodeDataChannel.preload();
|
|
23
|
+
}
|
|
24
|
+
export function initLogger(level: LogLevel): void {
|
|
25
|
+
nodeDataChannel.initLogger(level);
|
|
26
|
+
}
|
|
27
|
+
export function cleanup(): void {
|
|
28
|
+
nodeDataChannel.cleanup();
|
|
29
|
+
}
|
|
30
|
+
export function setSctpSettings(settings: SctpSettings): void {
|
|
31
|
+
nodeDataChannel.setSctpSettings(settings);
|
|
32
|
+
}
|
|
33
|
+
export function getLibraryVersion(): string {
|
|
34
|
+
return nodeDataChannel.getLibraryVersion();
|
|
35
|
+
}
|
|
12
36
|
|
|
13
37
|
export interface Audio {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
addAudioCodec(payloadType: number, codec: string, profile?: string): void;
|
|
39
|
+
addOpusCodec(payloadType: number, profile?: string): string;
|
|
40
|
+
direction(): Direction;
|
|
41
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
42
|
+
mid(): string;
|
|
43
|
+
setDirection(dir: Direction): void;
|
|
44
|
+
description(): string;
|
|
45
|
+
removeFormat(fmt: string): void;
|
|
46
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
47
|
+
removeSSRC(ssrc: number): void;
|
|
48
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
49
|
+
hasSSRC(ssrc: number): boolean;
|
|
50
|
+
getSSRCs(): number[];
|
|
51
|
+
getCNameForSsrc(ssrc: number): string;
|
|
52
|
+
setBitrate(bitRate: number): void;
|
|
53
|
+
getBitrate(): number;
|
|
54
|
+
hasPayloadType(payloadType: number): boolean;
|
|
55
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
56
|
+
addRTPMap(): void;
|
|
57
|
+
parseSdpLine(line: string): void;
|
|
34
58
|
}
|
|
35
59
|
export const Audio: {
|
|
36
|
-
|
|
37
|
-
} = nodeDataChannel.Audio
|
|
38
|
-
|
|
60
|
+
new (mid: string, dir: Direction): Audio;
|
|
61
|
+
} = nodeDataChannel.Audio;
|
|
39
62
|
|
|
40
63
|
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
|
-
|
|
64
|
+
addVideoCodec(payloadType: number, codec: string, profile?: string): void;
|
|
65
|
+
addH264Codec(payloadType: number, profile?: string): void;
|
|
66
|
+
addVP8Codec(payloadType: number): void;
|
|
67
|
+
addVP9Codec(payloadType: number): void;
|
|
68
|
+
direction(): Direction;
|
|
69
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
70
|
+
mid(): string;
|
|
71
|
+
setDirection(dir: Direction): void;
|
|
72
|
+
description(): string;
|
|
73
|
+
removeFormat(fmt: string): void;
|
|
74
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
75
|
+
removeSSRC(ssrc: number): void;
|
|
76
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
77
|
+
hasSSRC(ssrc: number): boolean;
|
|
78
|
+
getSSRCs(): number[];
|
|
79
|
+
getCNameForSsrc(ssrc: number): string;
|
|
80
|
+
setBitrate(bitRate: number): void;
|
|
81
|
+
getBitrate(): number;
|
|
82
|
+
hasPayloadType(payloadType: number): boolean;
|
|
83
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
84
|
+
addRTPMap(): void;
|
|
85
|
+
parseSdpLine(line: string): void;
|
|
63
86
|
}
|
|
64
87
|
export const Video: {
|
|
65
|
-
|
|
66
|
-
} = nodeDataChannel.Video
|
|
88
|
+
new (mid: string, dir: Direction): Video;
|
|
89
|
+
} = nodeDataChannel.Video;
|
|
67
90
|
|
|
68
91
|
export interface Track {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
direction(): Direction;
|
|
93
|
+
mid(): string;
|
|
94
|
+
type(): string;
|
|
95
|
+
close(): void;
|
|
96
|
+
sendMessage(msg: string): boolean;
|
|
97
|
+
sendMessageBinary(buffer: Buffer): boolean;
|
|
98
|
+
isOpen(): boolean;
|
|
99
|
+
isClosed(): boolean;
|
|
100
|
+
bufferedAmount(): number;
|
|
101
|
+
maxMessageSize(): number;
|
|
102
|
+
requestBitrate(bitRate: number): boolean;
|
|
103
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
104
|
+
requestKeyframe(): boolean;
|
|
105
|
+
setMediaHandler(handler: RtcpReceivingSession): void;
|
|
106
|
+
onOpen(cb: () => void): void;
|
|
107
|
+
onClosed(cb: () => void): void;
|
|
108
|
+
onError(cb: (err: string) => void): void;
|
|
109
|
+
onMessage(cb: (msg: Buffer) => void): void;
|
|
87
110
|
}
|
|
88
111
|
export const Track: {
|
|
89
|
-
|
|
90
|
-
} = nodeDataChannel.Track
|
|
112
|
+
new (): Track;
|
|
113
|
+
} = nodeDataChannel.Track;
|
|
91
114
|
|
|
92
115
|
export interface DataChannel extends Channel {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
116
|
+
getLabel(): string;
|
|
117
|
+
getId(): number;
|
|
118
|
+
getProtocol(): string;
|
|
96
119
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
// Channel implementation
|
|
121
|
+
close(): void;
|
|
122
|
+
sendMessage(msg: string): boolean;
|
|
123
|
+
sendMessageBinary(buffer: Buffer | Uint8Array): boolean;
|
|
124
|
+
isOpen(): boolean;
|
|
125
|
+
bufferedAmount(): number;
|
|
126
|
+
maxMessageSize(): number;
|
|
127
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
128
|
+
onOpen(cb: () => void): void;
|
|
129
|
+
onClosed(cb: () => void): void;
|
|
130
|
+
onError(cb: (err: string) => void): void;
|
|
131
|
+
onBufferedAmountLow(cb: () => void): void;
|
|
132
|
+
onMessage(cb: (msg: string | Buffer | ArrayBuffer) => void): void;
|
|
110
133
|
}
|
|
111
134
|
export const DataChannel: {
|
|
112
|
-
|
|
113
|
-
} = nodeDataChannel.DataChannel
|
|
135
|
+
// DataChannel implementation
|
|
136
|
+
} = nodeDataChannel.DataChannel;
|
|
114
137
|
|
|
115
138
|
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
|
-
|
|
139
|
+
close(): void;
|
|
140
|
+
setLocalDescription(type?: DescriptionType, init?: LocalDescriptionInit): void;
|
|
141
|
+
setRemoteDescription(sdp: string, type: DescriptionType): void;
|
|
142
|
+
localDescription(): { type: DescriptionType; sdp: string } | null;
|
|
143
|
+
remoteDescription(): { type: DescriptionType; sdp: string } | null;
|
|
144
|
+
remoteFingerprint(): CertificateFingerprint;
|
|
145
|
+
addRemoteCandidate(candidate: string, mid: string): void;
|
|
146
|
+
createDataChannel(label: string, config?: DataChannelInitConfig): DataChannel;
|
|
147
|
+
addTrack(media: Video | Audio): Track;
|
|
148
|
+
hasMedia(): boolean;
|
|
149
|
+
state(): RTCPeerConnectionState;
|
|
150
|
+
iceState(): RTCIceConnectionState;
|
|
151
|
+
signalingState(): RTCSignalingState;
|
|
152
|
+
gatheringState(): RTCIceGatheringState;
|
|
153
|
+
onLocalDescription(cb: (sdp: string, type: DescriptionType) => void): void;
|
|
154
|
+
onLocalCandidate(cb: (candidate: string, mid: string) => void): void;
|
|
155
|
+
onStateChange(cb: (state: string) => void): void;
|
|
156
|
+
onIceStateChange(cb: (state: string) => void): void;
|
|
157
|
+
onSignalingStateChange(cb: (state: string) => void): void;
|
|
158
|
+
onGatheringStateChange(cb: (state: string) => void): void;
|
|
159
|
+
onDataChannel(cb: (dc: DataChannel) => void): void;
|
|
160
|
+
onTrack(cb: (track: Track) => void): void;
|
|
161
|
+
bytesSent(): number;
|
|
162
|
+
bytesReceived(): number;
|
|
163
|
+
rtt(): number;
|
|
164
|
+
getSelectedCandidatePair(): {
|
|
165
|
+
local: SelectedCandidateInfo;
|
|
166
|
+
remote: SelectedCandidateInfo;
|
|
167
|
+
} | null;
|
|
168
|
+
maxDataChannelId(): number;
|
|
169
|
+
maxMessageSize(): number;
|
|
143
170
|
}
|
|
144
171
|
export const PeerConnection: {
|
|
145
|
-
|
|
146
|
-
} = nodeDataChannel.PeerConnection
|
|
172
|
+
new (peerName: string, config: RtcConfig): PeerConnection;
|
|
173
|
+
} = nodeDataChannel.PeerConnection;
|
|
147
174
|
|
|
148
|
-
export interface
|
|
175
|
+
export interface IceUdpMuxListener {
|
|
176
|
+
address?: string;
|
|
177
|
+
port: number;
|
|
178
|
+
stop(): void;
|
|
179
|
+
onUnhandledStunRequest(cb: (req: IceUdpMuxRequest) => void): void;
|
|
149
180
|
}
|
|
181
|
+
export const IceUdpMuxListener: {
|
|
182
|
+
new (port: number, address?: string): IceUdpMuxListener;
|
|
183
|
+
} = nodeDataChannel.IceUdpMuxListener;
|
|
184
|
+
|
|
185
|
+
export interface RtcpReceivingSession {}
|
|
150
186
|
|
|
151
187
|
export const RtcpReceivingSession: {
|
|
152
|
-
|
|
153
|
-
} = nodeDataChannel.RtcpReceivingSession
|
|
188
|
+
new (): RtcpReceivingSession;
|
|
189
|
+
} = nodeDataChannel.RtcpReceivingSession;
|
|
154
190
|
|
|
155
191
|
export { WebSocketServer } from './websocket-server';
|
|
156
192
|
export { WebSocket } from './websocket';
|
|
@@ -158,23 +194,23 @@ export { WebSocket } from './websocket';
|
|
|
158
194
|
export const DataChannelStream = _DataChannelStream;
|
|
159
195
|
|
|
160
196
|
export default {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
197
|
+
initLogger,
|
|
198
|
+
cleanup,
|
|
199
|
+
preload,
|
|
200
|
+
setSctpSettings,
|
|
201
|
+
getLibraryVersion,
|
|
202
|
+
RtcpReceivingSession,
|
|
203
|
+
Track,
|
|
204
|
+
Video,
|
|
205
|
+
Audio,
|
|
206
|
+
DataChannel,
|
|
207
|
+
PeerConnection,
|
|
208
|
+
WebSocket,
|
|
209
|
+
WebSocketServer,
|
|
210
|
+
DataChannelStream,
|
|
211
|
+
IceUdpMuxListener,
|
|
175
212
|
};
|
|
176
213
|
|
|
177
|
-
|
|
178
214
|
// Types
|
|
179
215
|
// https://github.com/murat-dogan/node-datachannel/issues/300
|
|
180
|
-
export *
|
|
216
|
+
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,134 @@ 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
|
+
disableAutoGathering?: boolean;
|
|
77
|
+
certificatePemFile?: string;
|
|
78
|
+
keyPemFile?: string;
|
|
79
|
+
keyPemPass?: string;
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
// Lowercase to match the description type string from libdatachannel
|
|
79
|
-
export type DescriptionType = 'unspec' | 'offer' | 'answer' | 'pranswer' | 'rollback'
|
|
83
|
+
export type DescriptionType = 'unspec' | 'offer' | 'answer' | 'pranswer' | 'rollback';
|
|
80
84
|
|
|
81
85
|
export type RTCSdpType = 'answer' | 'offer' | 'pranswer' | 'rollback';
|
|
82
86
|
|
|
83
|
-
export type RTCIceTransportState =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
export type RTCIceTransportState =
|
|
88
|
+
| 'checking'
|
|
89
|
+
| 'closed'
|
|
90
|
+
| 'completed'
|
|
91
|
+
| 'connected'
|
|
92
|
+
| 'disconnected'
|
|
93
|
+
| 'failed'
|
|
94
|
+
| 'new';
|
|
95
|
+
export type RTCPeerConnectionState =
|
|
96
|
+
| 'closed'
|
|
97
|
+
| 'connected'
|
|
98
|
+
| 'connecting'
|
|
99
|
+
| 'disconnected'
|
|
100
|
+
| 'failed'
|
|
101
|
+
| 'new';
|
|
102
|
+
export type RTCIceConnectionState =
|
|
103
|
+
| 'checking'
|
|
104
|
+
| 'closed'
|
|
105
|
+
| 'completed'
|
|
106
|
+
| 'connected'
|
|
107
|
+
| 'disconnected'
|
|
108
|
+
| 'failed'
|
|
109
|
+
| 'new';
|
|
110
|
+
export type RTCIceGathererState = 'complete' | 'gathering' | 'new';
|
|
111
|
+
export type RTCIceGatheringState = 'complete' | 'gathering' | 'new';
|
|
112
|
+
export type RTCSignalingState =
|
|
113
|
+
| 'closed'
|
|
114
|
+
| 'have-local-offer'
|
|
115
|
+
| 'have-local-pranswer'
|
|
116
|
+
| 'have-remote-offer'
|
|
117
|
+
| 'have-remote-pranswer'
|
|
118
|
+
| 'stable';
|
|
89
119
|
|
|
120
|
+
export interface LocalDescriptionInit {
|
|
121
|
+
iceUfrag?: string;
|
|
122
|
+
icePwd?: string;
|
|
123
|
+
}
|
|
90
124
|
|
|
91
125
|
export interface DataChannelInitConfig {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
126
|
+
protocol?: string;
|
|
127
|
+
negotiated?: boolean;
|
|
128
|
+
id?: number;
|
|
129
|
+
unordered?: boolean; // Reliability
|
|
130
|
+
maxPacketLifeTime?: number; // Reliability
|
|
131
|
+
maxRetransmits?: number; // Reliability
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface CertificateFingerprint {
|
|
135
|
+
/**
|
|
136
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCCertificate/getFingerprints#value
|
|
137
|
+
*/
|
|
138
|
+
value: string;
|
|
139
|
+
/**
|
|
140
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RTCCertificate/getFingerprints#algorithm
|
|
141
|
+
*/
|
|
142
|
+
algorithm: 'sha-1' | 'sha-224' | 'sha-256' | 'sha-384' | 'sha-512' | 'md5' | 'md2';
|
|
98
143
|
}
|
|
99
144
|
|
|
100
145
|
export interface SelectedCandidateInfo {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
146
|
+
address: string;
|
|
147
|
+
port: number;
|
|
148
|
+
type: string;
|
|
149
|
+
transportType: string;
|
|
150
|
+
candidate: string;
|
|
151
|
+
mid: string;
|
|
152
|
+
priority: number;
|
|
108
153
|
}
|
|
109
154
|
|
|
110
155
|
// Must be same as rtc enum class Direction
|
|
111
|
-
export type Direction = 'SendOnly' | 'RecvOnly' | 'SendRecv' | 'Inactive' | 'Unknown'
|
|
156
|
+
export type Direction = 'SendOnly' | 'RecvOnly' | 'SendRecv' | 'Inactive' | 'Unknown';
|
|
157
|
+
|
|
158
|
+
export interface IceUdpMuxRequest {
|
|
159
|
+
ufrag: string;
|
|
160
|
+
host: string;
|
|
161
|
+
port: number;
|
|
162
|
+
}
|
|
@@ -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
|
}
|