node-rtc-connection 1.0.12 → 1.0.15
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/README.md +355 -289
- package/dist/index.cjs +4357 -3092
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +4357 -3092
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
- package/src/datachannel/RTCDataChannel.js +354 -0
- package/src/dtls/RTCCertificate.js +310 -0
- package/src/dtls/RTCDtlsTransport.js +247 -0
- package/src/foundation/ByteBufferQueue.js +235 -0
- package/src/foundation/RTCError.js +226 -0
- package/src/ice/RTCIceCandidate.js +301 -0
- package/src/ice/RTCIceTransport.js +998 -0
- package/src/index.d.ts +316 -145
- package/src/index.js +78 -45
- package/src/network/network-transport.js +478 -0
- package/src/peerconnection/RTCPeerConnection.js +847 -0
- package/src/sctp/RTCSctpTransport.js +253 -0
- package/src/sdp/RTCSessionDescription.js +102 -0
- package/src/sdp/sdp-utils.js +224 -0
- package/src/stun/stun-client.js +643 -0
- package/src/ICEGatherer.js +0 -341
- package/src/NativePeerConnectionFactory.js +0 -1044
- package/src/RTCDataChannel.js +0 -346
- package/src/RTCDataChannelEvent.js +0 -50
- package/src/RTCError.js +0 -66
- package/src/RTCIceCandidate.js +0 -184
- package/src/RTCPeerConnection.js +0 -505
- package/src/RTCPeerConnectionIceEvent.js +0 -58
- package/src/RTCSessionDescription.js +0 -62
- package/src/STUNClient.js +0 -222
- package/src/SecureConnection.js +0 -298
- package/src/TURNClient.js +0 -561
- package/src/UDPTransport.js +0 -236
package/src/index.d.ts
CHANGED
|
@@ -4,73 +4,252 @@
|
|
|
4
4
|
|
|
5
5
|
/// <reference types="node" />
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
/**
|
|
8
|
+
* ByteBufferQueue - Efficient byte buffer with O(1) append and O(n) read
|
|
9
|
+
*/
|
|
10
|
+
export class ByteBufferQueue {
|
|
11
|
+
constructor();
|
|
12
|
+
readonly size: number;
|
|
13
|
+
readonly empty: boolean;
|
|
14
|
+
readInto(buffer: Buffer): number;
|
|
15
|
+
append(buffer: Buffer): void;
|
|
16
|
+
clear(): void;
|
|
17
|
+
read(n: number): Buffer;
|
|
18
|
+
peek(n?: number): Buffer;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* RTCError - WebRTC-specific error types
|
|
23
|
+
*/
|
|
24
|
+
export interface RTCErrorInit {
|
|
25
|
+
errorDetail?: string;
|
|
26
|
+
sdpLineNumber?: number;
|
|
27
|
+
httpRequestStatusCode?: number;
|
|
28
|
+
sctpCauseCode?: number;
|
|
29
|
+
receivedAlert?: number;
|
|
30
|
+
sentAlert?: number;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
export interface RTCErrorDetailType {
|
|
34
|
+
NONE: string;
|
|
35
|
+
DATA_CHANNEL_FAILURE: string;
|
|
36
|
+
DTLS_FAILURE: string;
|
|
37
|
+
FINGERPRINT_FAILURE: string;
|
|
38
|
+
SCTP_FAILURE: string;
|
|
39
|
+
SDP_SYNTAX_ERROR: string;
|
|
40
|
+
HARDWARE_ENCODER_NOT_AVAILABLE: string;
|
|
41
|
+
HARDWARE_ENCODER_ERROR: string;
|
|
42
|
+
INVALID_STATE: string;
|
|
43
|
+
INVALID_MODIFICATION: string;
|
|
44
|
+
INVALID_ACCESS_ERROR: string;
|
|
45
|
+
OPERATION_ERROR: string;
|
|
31
46
|
}
|
|
32
47
|
|
|
33
|
-
export class
|
|
34
|
-
constructor(
|
|
35
|
-
readonly
|
|
36
|
-
readonly
|
|
37
|
-
|
|
48
|
+
export class RTCError extends Error {
|
|
49
|
+
constructor(init?: RTCErrorInit, message?: string);
|
|
50
|
+
readonly errorDetail: string;
|
|
51
|
+
readonly sdpLineNumber: number | null;
|
|
52
|
+
readonly httpRequestStatusCode: number | null;
|
|
53
|
+
readonly sctpCauseCode: number | null;
|
|
54
|
+
readonly receivedAlert: number | null;
|
|
55
|
+
readonly sentAlert: number | null;
|
|
56
|
+
toJSON(): object;
|
|
57
|
+
static fromNative(nativeError: any): RTCError;
|
|
58
|
+
static DetailType: RTCErrorDetailType;
|
|
38
59
|
}
|
|
39
60
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export type RTCIceTcpCandidateType = 'active' | 'passive' | 'so';
|
|
44
|
-
|
|
61
|
+
/**
|
|
62
|
+
* RTCIceCandidate - ICE candidate representation
|
|
63
|
+
*/
|
|
45
64
|
export interface RTCIceCandidateInit {
|
|
46
65
|
candidate?: string;
|
|
47
66
|
sdpMid?: string | null;
|
|
48
67
|
sdpMLineIndex?: number | null;
|
|
49
|
-
usernameFragment?: string
|
|
68
|
+
usernameFragment?: string;
|
|
50
69
|
}
|
|
51
70
|
|
|
52
71
|
export class RTCIceCandidate {
|
|
53
|
-
constructor(
|
|
72
|
+
constructor(candidateInit?: RTCIceCandidateInit);
|
|
54
73
|
readonly candidate: string;
|
|
55
74
|
readonly sdpMid: string | null;
|
|
56
75
|
readonly sdpMLineIndex: number | null;
|
|
76
|
+
readonly usernameFragment: string | null;
|
|
57
77
|
readonly foundation: string | null;
|
|
58
|
-
readonly component:
|
|
78
|
+
readonly component: string | null;
|
|
59
79
|
readonly priority: number | null;
|
|
60
80
|
readonly address: string | null;
|
|
61
|
-
readonly protocol:
|
|
81
|
+
readonly protocol: string | null;
|
|
62
82
|
readonly port: number | null;
|
|
63
|
-
readonly type:
|
|
64
|
-
readonly tcpType:
|
|
83
|
+
readonly type: string | null;
|
|
84
|
+
readonly tcpType: string | null;
|
|
65
85
|
readonly relatedAddress: string | null;
|
|
66
86
|
readonly relatedPort: number | null;
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
toJSON(): object;
|
|
88
|
+
static fromString(candidateStr: string, sdpMid?: string | null, sdpMLineIndex?: number | null): RTCIceCandidate;
|
|
89
|
+
static isValid(candidateStr: string): boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* RTCIceTransport - ICE transport layer
|
|
94
|
+
*/
|
|
95
|
+
export enum RTCIceRole {
|
|
96
|
+
CONTROLLING = 'controlling',
|
|
97
|
+
CONTROLLED = 'controlled'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export enum RTCIceTransportState {
|
|
101
|
+
NEW = 'new',
|
|
102
|
+
CHECKING = 'checking',
|
|
103
|
+
CONNECTED = 'connected',
|
|
104
|
+
COMPLETED = 'completed',
|
|
105
|
+
DISCONNECTED = 'disconnected',
|
|
106
|
+
FAILED = 'failed',
|
|
107
|
+
CLOSED = 'closed'
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export enum RTCIceGatheringState {
|
|
111
|
+
NEW = 'new',
|
|
112
|
+
GATHERING = 'gathering',
|
|
113
|
+
COMPLETE = 'complete'
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface RTCIceParameters {
|
|
117
|
+
usernameFragment: string;
|
|
118
|
+
password: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface RTCIceCandidatePair {
|
|
122
|
+
local: RTCIceCandidate;
|
|
123
|
+
remote: RTCIceCandidate;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface RTCIceGatherOptions {
|
|
127
|
+
gatherPolicy?: 'all' | 'relay';
|
|
128
|
+
iceServers?: Array<any>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
import { EventEmitter } from 'events';
|
|
132
|
+
|
|
133
|
+
export class RTCIceTransport extends EventEmitter {
|
|
134
|
+
constructor();
|
|
135
|
+
readonly role: string | null;
|
|
136
|
+
readonly state: string;
|
|
137
|
+
readonly gatheringState: string;
|
|
138
|
+
getLocalCandidates(): RTCIceCandidate[];
|
|
139
|
+
getRemoteCandidates(): RTCIceCandidate[];
|
|
140
|
+
getSelectedCandidatePair(): RTCIceCandidatePair | null;
|
|
141
|
+
getLocalParameters(): RTCIceParameters | null;
|
|
142
|
+
getRemoteParameters(): RTCIceParameters | null;
|
|
143
|
+
gather(options?: RTCIceGatherOptions): void;
|
|
144
|
+
start(remoteParameters: RTCIceParameters, role: string): void;
|
|
145
|
+
stop(): void;
|
|
146
|
+
addRemoteCandidate(candidate: RTCIceCandidate): void;
|
|
147
|
+
isClosed(): boolean;
|
|
148
|
+
isStarted(): boolean;
|
|
149
|
+
|
|
150
|
+
on(event: 'statechange', listener: () => void): this;
|
|
151
|
+
on(event: 'gatheringstatechange', listener: () => void): this;
|
|
152
|
+
on(event: 'selectedcandidatepairchange', listener: () => void): this;
|
|
153
|
+
on(event: 'icecandidate', listener: (candidate: RTCIceCandidate) => void): this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* RTCCertificate - DTLS certificate
|
|
158
|
+
*/
|
|
159
|
+
export interface RTCDtlsFingerprint {
|
|
160
|
+
algorithm: string;
|
|
161
|
+
value: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface RTCCertificatePEM {
|
|
165
|
+
pemPrivateKey: string;
|
|
166
|
+
pemCertificate: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface RTCCertificateOptions {
|
|
170
|
+
name?: string;
|
|
171
|
+
expires?: number;
|
|
172
|
+
days?: number;
|
|
173
|
+
hash?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface RTCKeyParams {
|
|
177
|
+
type: 'RSA' | 'ECDSA';
|
|
178
|
+
rsaModulusLength?: number;
|
|
179
|
+
namedCurve?: string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export class RTCCertificate {
|
|
183
|
+
readonly expires: number;
|
|
184
|
+
getFingerprints(): RTCDtlsFingerprint[];
|
|
185
|
+
getPrivateKey(): string;
|
|
186
|
+
getPublicKey(): string;
|
|
187
|
+
toPEM(): RTCCertificatePEM;
|
|
188
|
+
isExpired(): boolean;
|
|
189
|
+
|
|
190
|
+
static generateCertificate(options?: RTCCertificateOptions): Promise<RTCCertificate>;
|
|
191
|
+
static fromPEM(pemPrivateKey: string, pemCertificate: string, expires?: number): RTCCertificate;
|
|
192
|
+
static isSupportedKeyParams(keyParams: RTCKeyParams): boolean;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* RTCDtlsTransport - DTLS transport layer
|
|
197
|
+
*/
|
|
198
|
+
export enum RTCDtlsTransportState {
|
|
199
|
+
NEW = 'new',
|
|
200
|
+
CONNECTING = 'connecting',
|
|
201
|
+
CONNECTED = 'connected',
|
|
202
|
+
CLOSED = 'closed',
|
|
203
|
+
FAILED = 'failed'
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export class RTCDtlsTransport extends EventEmitter {
|
|
207
|
+
constructor(iceTransport: RTCIceTransport);
|
|
208
|
+
readonly iceTransport: RTCIceTransport;
|
|
209
|
+
readonly state: string;
|
|
210
|
+
getRemoteCertificates(): ArrayBuffer[];
|
|
211
|
+
close(): void;
|
|
212
|
+
isClosed(): boolean;
|
|
213
|
+
|
|
214
|
+
on(event: 'statechange', listener: () => void): this;
|
|
215
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* RTCSctpTransport - SCTP transport layer
|
|
220
|
+
*/
|
|
221
|
+
export enum RTCSctpTransportState {
|
|
222
|
+
CONNECTING = 'connecting',
|
|
223
|
+
CONNECTED = 'connected',
|
|
224
|
+
CLOSED = 'closed'
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface RTCSctpTransportOptions {
|
|
228
|
+
maxMessageSize?: number;
|
|
229
|
+
maxChannels?: number;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class RTCSctpTransport extends EventEmitter {
|
|
233
|
+
constructor(dtlsTransport: RTCDtlsTransport, options?: RTCSctpTransportOptions);
|
|
234
|
+
readonly transport: RTCDtlsTransport;
|
|
235
|
+
readonly state: string;
|
|
236
|
+
readonly maxMessageSize: number;
|
|
237
|
+
readonly maxChannels: number | null;
|
|
238
|
+
close(): void;
|
|
239
|
+
isClosed(): boolean;
|
|
240
|
+
|
|
241
|
+
on(event: 'statechange', listener: () => void): this;
|
|
69
242
|
}
|
|
70
243
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
244
|
+
/**
|
|
245
|
+
* RTCDataChannel - Bidirectional data channel
|
|
246
|
+
*/
|
|
247
|
+
export enum RTCDataChannelState {
|
|
248
|
+
CONNECTING = 'connecting',
|
|
249
|
+
OPEN = 'open',
|
|
250
|
+
CLOSING = 'closing',
|
|
251
|
+
CLOSED = 'closed'
|
|
252
|
+
}
|
|
74
253
|
|
|
75
254
|
export interface RTCDataChannelInit {
|
|
76
255
|
ordered?: boolean;
|
|
@@ -81,15 +260,12 @@ export interface RTCDataChannelInit {
|
|
|
81
260
|
id?: number;
|
|
82
261
|
}
|
|
83
262
|
|
|
84
|
-
export interface
|
|
85
|
-
|
|
86
|
-
message: MessageEvent;
|
|
87
|
-
error: RTCErrorEvent;
|
|
88
|
-
close: Event;
|
|
89
|
-
bufferedamountlow: Event;
|
|
263
|
+
export interface RTCDataChannelMessageEvent {
|
|
264
|
+
data: string | Buffer | ArrayBuffer;
|
|
90
265
|
}
|
|
91
266
|
|
|
92
267
|
export class RTCDataChannel extends EventEmitter {
|
|
268
|
+
constructor(label: string, init?: RTCDataChannelInit);
|
|
93
269
|
readonly label: string;
|
|
94
270
|
readonly ordered: boolean;
|
|
95
271
|
readonly maxPacketLifeTime: number | null;
|
|
@@ -97,133 +273,128 @@ export class RTCDataChannel extends EventEmitter {
|
|
|
97
273
|
readonly protocol: string;
|
|
98
274
|
readonly negotiated: boolean;
|
|
99
275
|
readonly id: number | null;
|
|
100
|
-
readonly readyState:
|
|
276
|
+
readonly readyState: string;
|
|
101
277
|
readonly bufferedAmount: number;
|
|
102
278
|
bufferedAmountLowThreshold: number;
|
|
103
|
-
binaryType:
|
|
104
|
-
|
|
105
|
-
|
|
279
|
+
binaryType: 'arraybuffer' | 'blob';
|
|
280
|
+
readonly reliable: boolean;
|
|
281
|
+
|
|
106
282
|
send(data: string | ArrayBuffer | ArrayBufferView): void;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
283
|
+
close(): void;
|
|
284
|
+
|
|
285
|
+
on(event: 'open', listener: () => void): this;
|
|
286
|
+
on(event: 'message', listener: (event: RTCDataChannelMessageEvent) => void): this;
|
|
287
|
+
on(event: 'bufferedamountlow', listener: () => void): this;
|
|
288
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
289
|
+
on(event: 'closing', listener: () => void): this;
|
|
290
|
+
on(event: 'close', listener: () => void): this;
|
|
112
291
|
}
|
|
113
292
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
293
|
+
/**
|
|
294
|
+
* RTCSessionDescription - SDP representation
|
|
295
|
+
*/
|
|
296
|
+
export enum RTCSdpType {
|
|
297
|
+
OFFER = 'offer',
|
|
298
|
+
PRANSWER = 'pranswer',
|
|
299
|
+
ANSWER = 'answer',
|
|
300
|
+
ROLLBACK = 'rollback'
|
|
301
|
+
}
|
|
122
302
|
|
|
123
|
-
export
|
|
124
|
-
|
|
303
|
+
export interface RTCSessionDescriptionInit {
|
|
304
|
+
type?: string;
|
|
305
|
+
sdp?: string;
|
|
306
|
+
}
|
|
125
307
|
|
|
126
|
-
export
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
308
|
+
export class RTCSessionDescription {
|
|
309
|
+
constructor(init?: RTCSessionDescriptionInit);
|
|
310
|
+
type: string | null;
|
|
311
|
+
sdp: string | null;
|
|
312
|
+
toJSON(): RTCSessionDescriptionInit;
|
|
130
313
|
}
|
|
131
314
|
|
|
132
|
-
|
|
133
|
-
|
|
315
|
+
/**
|
|
316
|
+
* RTCPeerConnection - Main peer connection class
|
|
317
|
+
*/
|
|
318
|
+
export enum RTCSignalingState {
|
|
319
|
+
STABLE = 'stable',
|
|
320
|
+
HAVE_LOCAL_OFFER = 'have-local-offer',
|
|
321
|
+
HAVE_REMOTE_OFFER = 'have-remote-offer',
|
|
322
|
+
HAVE_LOCAL_PRANSWER = 'have-local-pranswer',
|
|
323
|
+
HAVE_REMOTE_PRANSWER = 'have-remote-pranswer',
|
|
324
|
+
CLOSED = 'closed'
|
|
134
325
|
}
|
|
135
326
|
|
|
136
|
-
export
|
|
137
|
-
|
|
327
|
+
export enum RTCIceGatheringState {
|
|
328
|
+
NEW = 'new',
|
|
329
|
+
GATHERING = 'gathering',
|
|
330
|
+
COMPLETE = 'complete'
|
|
138
331
|
}
|
|
139
332
|
|
|
140
|
-
export
|
|
141
|
-
|
|
142
|
-
|
|
333
|
+
export enum RTCPeerConnectionState {
|
|
334
|
+
NEW = 'new',
|
|
335
|
+
CONNECTING = 'connecting',
|
|
336
|
+
CONNECTED = 'connected',
|
|
337
|
+
DISCONNECTED = 'disconnected',
|
|
338
|
+
FAILED = 'failed',
|
|
339
|
+
CLOSED = 'closed'
|
|
143
340
|
}
|
|
144
341
|
|
|
145
|
-
export interface
|
|
146
|
-
|
|
147
|
-
|
|
342
|
+
export interface RTCIceServer {
|
|
343
|
+
urls: string | string[];
|
|
344
|
+
username?: string;
|
|
345
|
+
credential?: string;
|
|
148
346
|
}
|
|
149
347
|
|
|
150
|
-
export
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
348
|
+
export interface RTCConfiguration {
|
|
349
|
+
iceServers?: RTCIceServer[];
|
|
350
|
+
iceTransportPolicy?: 'all' | 'relay';
|
|
351
|
+
bundlePolicy?: 'balanced' | 'max-compat' | 'max-bundle';
|
|
154
352
|
}
|
|
155
353
|
|
|
156
|
-
export interface
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
iceconnectionstatechange: Event;
|
|
162
|
-
icegatheringstatechange: Event;
|
|
163
|
-
negotiationneeded: Event;
|
|
164
|
-
signalingstatechange: Event;
|
|
354
|
+
export interface RTCIceCandidateInit {
|
|
355
|
+
candidate?: string;
|
|
356
|
+
sdpMid?: string | null;
|
|
357
|
+
sdpMLineIndex?: number | null;
|
|
358
|
+
usernameFragment?: string | null;
|
|
165
359
|
}
|
|
166
360
|
|
|
167
361
|
export class RTCPeerConnection extends EventEmitter {
|
|
168
|
-
constructor(configuration?: RTCConfiguration
|
|
169
|
-
|
|
170
|
-
readonly signalingState:
|
|
171
|
-
readonly iceGatheringState:
|
|
172
|
-
readonly iceConnectionState:
|
|
173
|
-
readonly connectionState:
|
|
362
|
+
constructor(configuration?: RTCConfiguration);
|
|
363
|
+
|
|
364
|
+
readonly signalingState: string;
|
|
365
|
+
readonly iceGatheringState: string;
|
|
366
|
+
readonly iceConnectionState: string;
|
|
367
|
+
readonly connectionState: string;
|
|
174
368
|
readonly localDescription: RTCSessionDescription | null;
|
|
175
369
|
readonly remoteDescription: RTCSessionDescription | null;
|
|
176
|
-
readonly pendingLocalDescription: RTCSessionDescription | null;
|
|
177
|
-
readonly pendingRemoteDescription: RTCSessionDescription | null;
|
|
178
370
|
readonly currentLocalDescription: RTCSessionDescription | null;
|
|
371
|
+
readonly pendingLocalDescription: RTCSessionDescription | null;
|
|
179
372
|
readonly currentRemoteDescription: RTCSessionDescription | null;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
373
|
+
readonly pendingRemoteDescription: RTCSessionDescription | null;
|
|
374
|
+
readonly canTrickleIceCandidates: boolean;
|
|
375
|
+
readonly sctp: RTCSctpTransport | null;
|
|
376
|
+
|
|
377
|
+
createDataChannel(label: string, options?: RTCDataChannelInit): RTCDataChannel;
|
|
378
|
+
createOffer(options?: any): Promise<RTCSessionDescription>;
|
|
379
|
+
createAnswer(options?: any): Promise<RTCSessionDescription>;
|
|
380
|
+
setLocalDescription(description?: RTCSessionDescription): Promise<void>;
|
|
381
|
+
setRemoteDescription(description: RTCSessionDescription): Promise<void>;
|
|
382
|
+
addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void>;
|
|
187
383
|
getConfiguration(): RTCConfiguration;
|
|
188
384
|
setConfiguration(configuration: RTCConfiguration): void;
|
|
189
385
|
close(): void;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
on
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// RTCError
|
|
199
|
-
export class RTCError extends Error {
|
|
200
|
-
constructor(message: string, errorDetail?: string);
|
|
201
|
-
readonly errorDetail: string;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export interface RTCErrorEventInit {
|
|
205
|
-
error: RTCError;
|
|
386
|
+
|
|
387
|
+
on(event: 'negotiationneeded', listener: () => void): this;
|
|
388
|
+
on(event: 'icecandidate', listener: (event: { candidate: RTCIceCandidateInit | null }) => void): this;
|
|
389
|
+
on(event: 'icegatheringstatechange', listener: () => void): this;
|
|
390
|
+
on(event: 'iceconnectionstatechange', listener: () => void): this;
|
|
391
|
+
on(event: 'connectionstatechange', listener: () => void): this;
|
|
392
|
+
on(event: 'signalingstatechange', listener: () => void): this;
|
|
393
|
+
on(event: 'datachannel', listener: (event: { channel: RTCDataChannel }) => void): this;
|
|
206
394
|
}
|
|
207
395
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
// NativePeerConnectionFactory
|
|
214
|
-
export class NativePeerConnectionFactory {
|
|
215
|
-
constructor();
|
|
216
|
-
initialize(): void;
|
|
217
|
-
createPeerConnection(configuration: RTCConfiguration): any;
|
|
218
|
-
dispose(): void;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Factory functions
|
|
222
|
-
export function createPeerConnection(configuration?: RTCConfiguration): RTCPeerConnection;
|
|
223
|
-
export function createPeerConnectionWithFactory(configuration: RTCConfiguration, factory: NativePeerConnectionFactory): RTCPeerConnection;
|
|
224
|
-
|
|
225
|
-
// Alias
|
|
226
|
-
export { RTCPeerConnection as RTCConnection };
|
|
396
|
+
/**
|
|
397
|
+
* Package version
|
|
398
|
+
*/
|
|
399
|
+
export const version: string;
|
|
227
400
|
|
|
228
|
-
// Default factory instance
|
|
229
|
-
export const defaultFactory: NativePeerConnectionFactory;
|
package/src/index.js
CHANGED
|
@@ -1,59 +1,92 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Ported from Chromium's PeerConnection implementation
|
|
2
|
+
* @fileoverview node-rtc-connection - WebRTC DataChannel implementation for Node.js
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A clean-room implementation of WebRTC peer connections and data channels
|
|
5
|
+
* for Node.js, ported from Chromium's production WebRTC code.
|
|
6
|
+
*
|
|
7
|
+
* This implementation focuses on DataChannel functionality without media streams.
|
|
8
|
+
* Features:
|
|
9
|
+
* - ICE (Interactive Connectivity Establishment)
|
|
10
|
+
* - STUN/TURN support for NAT traversal
|
|
11
|
+
* - DTLS encryption
|
|
12
|
+
* - SCTP for reliable data channels
|
|
13
|
+
* - Full WebRTC API compatibility
|
|
14
|
+
*
|
|
15
|
+
* @license BSD-3-Clause
|
|
16
|
+
* @author nmhung1210
|
|
7
17
|
*/
|
|
8
18
|
|
|
9
|
-
|
|
10
|
-
const RTCDataChannel = require('./RTCDataChannel');
|
|
11
|
-
const RTCSessionDescription = require('./RTCSessionDescription');
|
|
12
|
-
const RTCIceCandidate = require('./RTCIceCandidate');
|
|
13
|
-
const RTCDataChannelEvent = require('./RTCDataChannelEvent');
|
|
14
|
-
const RTCPeerConnectionIceEvent = require('./RTCPeerConnectionIceEvent');
|
|
15
|
-
const { RTCError, RTCErrorEvent } = require('./RTCError');
|
|
16
|
-
const NativePeerConnectionFactory = require('./NativePeerConnectionFactory');
|
|
19
|
+
'use strict';
|
|
17
20
|
|
|
18
|
-
//
|
|
19
|
-
const
|
|
21
|
+
// Foundation Layer
|
|
22
|
+
const ByteBufferQueue = require('./foundation/ByteBufferQueue');
|
|
23
|
+
const RTCError = require('./foundation/RTCError');
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
25
|
+
// ICE Layer
|
|
26
|
+
const RTCIceCandidate = require('./ice/RTCIceCandidate');
|
|
27
|
+
const {
|
|
28
|
+
RTCIceTransport,
|
|
29
|
+
RTCIceRole,
|
|
30
|
+
RTCIceTransportState,
|
|
31
|
+
RTCIceGatheringState
|
|
32
|
+
} = require('./ice/RTCIceTransport');
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @param {NativePeerConnectionFactory} factory - Custom factory
|
|
34
|
-
* @returns {RTCPeerConnection}
|
|
35
|
-
*/
|
|
36
|
-
function createPeerConnectionWithFactory(configuration, factory) {
|
|
37
|
-
return new RTCPeerConnection(configuration, factory);
|
|
38
|
-
}
|
|
34
|
+
// DTLS Layer
|
|
35
|
+
const RTCCertificate = require('./dtls/RTCCertificate');
|
|
36
|
+
const { RTCDtlsTransport, RTCDtlsTransportState } = require('./dtls/RTCDtlsTransport');
|
|
39
37
|
|
|
38
|
+
// SCTP Layer
|
|
39
|
+
const { RTCSctpTransport, RTCSctpTransportState } = require('./sctp/RTCSctpTransport');
|
|
40
|
+
|
|
41
|
+
// DataChannel Layer
|
|
42
|
+
const { RTCDataChannel, RTCDataChannelState } = require('./datachannel/RTCDataChannel');
|
|
43
|
+
|
|
44
|
+
// SDP Layer
|
|
45
|
+
const { RTCSessionDescription, RTCSdpType } = require('./sdp/RTCSessionDescription');
|
|
46
|
+
|
|
47
|
+
// PeerConnection Layer
|
|
48
|
+
const {
|
|
49
|
+
RTCPeerConnection,
|
|
50
|
+
RTCSignalingState,
|
|
51
|
+
RTCIceGatheringState: RTCIceGatheringStatePC,
|
|
52
|
+
RTCPeerConnectionState
|
|
53
|
+
} = require('./peerconnection/RTCPeerConnection');
|
|
54
|
+
|
|
55
|
+
// Export all public APIs
|
|
40
56
|
module.exports = {
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
// Foundation
|
|
58
|
+
ByteBufferQueue,
|
|
59
|
+
RTCError,
|
|
60
|
+
|
|
61
|
+
// ICE
|
|
62
|
+
RTCIceCandidate,
|
|
63
|
+
RTCIceTransport,
|
|
64
|
+
RTCIceRole,
|
|
65
|
+
RTCIceTransportState,
|
|
66
|
+
RTCIceGatheringState,
|
|
67
|
+
|
|
68
|
+
// DTLS
|
|
69
|
+
RTCCertificate,
|
|
70
|
+
RTCDtlsTransport,
|
|
71
|
+
RTCDtlsTransportState,
|
|
72
|
+
|
|
73
|
+
// SCTP
|
|
74
|
+
RTCSctpTransport,
|
|
75
|
+
RTCSctpTransportState,
|
|
46
76
|
|
|
47
|
-
//
|
|
77
|
+
// DataChannel
|
|
48
78
|
RTCDataChannel,
|
|
79
|
+
RTCDataChannelState,
|
|
80
|
+
|
|
81
|
+
// SDP
|
|
49
82
|
RTCSessionDescription,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
83
|
+
RTCSdpType,
|
|
84
|
+
|
|
85
|
+
// PeerConnection
|
|
86
|
+
RTCPeerConnection,
|
|
87
|
+
RTCSignalingState,
|
|
88
|
+
RTCPeerConnectionState,
|
|
55
89
|
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
defaultFactory
|
|
90
|
+
// Version
|
|
91
|
+
version: require('../package.json').version
|
|
59
92
|
};
|