node-rtc-connection 1.0.12 → 1.0.14

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/src/index.d.ts CHANGED
@@ -4,73 +4,252 @@
4
4
 
5
5
  /// <reference types="node" />
6
6
 
7
- import { EventEmitter } from 'events';
8
-
9
- // RTCConfiguration
10
- export interface RTCIceServer {
11
- urls: string | string[];
12
- username?: string;
13
- credential?: string;
14
- credentialType?: 'password' | 'oauth';
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
- export interface RTCConfiguration {
18
- iceServers?: RTCIceServer[];
19
- iceTransportPolicy?: 'all' | 'relay';
20
- bundlePolicy?: 'balanced' | 'max-compat' | 'max-bundle';
21
- rtcpMuxPolicy?: 'negotiate' | 'require';
22
- iceCandidatePoolSize?: number;
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
- // RTCSessionDescription
26
- export type RTCSdpType = 'offer' | 'answer' | 'pranswer' | 'rollback';
27
-
28
- export interface RTCSessionDescriptionInit {
29
- type: RTCSdpType;
30
- sdp?: string;
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 RTCSessionDescription {
34
- constructor(descriptionInitDict?: RTCSessionDescriptionInit);
35
- readonly type: RTCSdpType;
36
- readonly sdp: string;
37
- toJSON(): RTCSessionDescriptionInit;
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
- // RTCIceCandidate
41
- export type RTCIceCandidateType = 'host' | 'srflx' | 'prflx' | 'relay';
42
- export type RTCIceProtocol = 'udp' | 'tcp';
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 | null;
68
+ usernameFragment?: string;
50
69
  }
51
70
 
52
71
  export class RTCIceCandidate {
53
- constructor(candidateInitDict?: RTCIceCandidateInit);
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: 'rtp' | 'rtcp' | null;
78
+ readonly component: string | null;
59
79
  readonly priority: number | null;
60
80
  readonly address: string | null;
61
- readonly protocol: RTCIceProtocol | null;
81
+ readonly protocol: string | null;
62
82
  readonly port: number | null;
63
- readonly type: RTCIceCandidateType | null;
64
- readonly tcpType: RTCIceTcpCandidateType | null;
83
+ readonly type: string | null;
84
+ readonly tcpType: string | null;
65
85
  readonly relatedAddress: string | null;
66
86
  readonly relatedPort: number | null;
67
- readonly usernameFragment: string | null;
68
- toJSON(): RTCIceCandidateInit;
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
- // RTCDataChannel
72
- export type RTCDataChannelState = 'connecting' | 'open' | 'closing' | 'closed';
73
- export type RTCBinaryType = 'blob' | 'arraybuffer';
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 RTCDataChannelEventMap {
85
- open: Event;
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: RTCDataChannelState;
276
+ readonly readyState: string;
101
277
  readonly bufferedAmount: number;
102
278
  bufferedAmountLowThreshold: number;
103
- binaryType: RTCBinaryType;
104
-
105
- close(): void;
279
+ binaryType: 'arraybuffer' | 'blob';
280
+ readonly reliable: boolean;
281
+
106
282
  send(data: string | ArrayBuffer | ArrayBufferView): void;
107
-
108
- on<K extends keyof RTCDataChannelEventMap>(event: K, listener: (ev: RTCDataChannelEventMap[K]) => void): this;
109
- once<K extends keyof RTCDataChannelEventMap>(event: K, listener: (ev: RTCDataChannelEventMap[K]) => void): this;
110
- off<K extends keyof RTCDataChannelEventMap>(event: K, listener: (ev: RTCDataChannelEventMap[K]) => void): this;
111
- emit<K extends keyof RTCDataChannelEventMap>(event: K, ...args: any[]): boolean;
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
- // RTCPeerConnection
115
- export type RTCSignalingState = 'stable' | 'have-local-offer' | 'have-remote-offer' |
116
- 'have-local-pranswer' | 'have-remote-pranswer' | 'closed';
117
-
118
- export type RTCIceGatheringState = 'new' | 'gathering' | 'complete';
119
-
120
- export type RTCIceConnectionState = 'new' | 'checking' | 'connected' | 'completed' |
121
- 'failed' | 'disconnected' | 'closed';
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 type RTCPeerConnectionState = 'new' | 'connecting' | 'connected' |
124
- 'disconnected' | 'failed' | 'closed';
303
+ export interface RTCSessionDescriptionInit {
304
+ type?: string;
305
+ sdp?: string;
306
+ }
125
307
 
126
- export interface RTCOfferOptions {
127
- iceRestart?: boolean;
128
- offerToReceiveAudio?: boolean;
129
- offerToReceiveVideo?: boolean;
308
+ export class RTCSessionDescription {
309
+ constructor(init?: RTCSessionDescriptionInit);
310
+ type: string | null;
311
+ sdp: string | null;
312
+ toJSON(): RTCSessionDescriptionInit;
130
313
  }
131
314
 
132
- export interface RTCAnswerOptions {
133
- iceRestart?: boolean;
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 interface RTCDataChannelEventInit {
137
- channel: RTCDataChannel;
327
+ export enum RTCIceGatheringState {
328
+ NEW = 'new',
329
+ GATHERING = 'gathering',
330
+ COMPLETE = 'complete'
138
331
  }
139
332
 
140
- export class RTCDataChannelEvent extends Event {
141
- constructor(type: string, eventInitDict: RTCDataChannelEventInit);
142
- readonly channel: RTCDataChannel;
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 RTCPeerConnectionIceEventInit {
146
- candidate?: RTCIceCandidate | null;
147
- url?: string | null;
342
+ export interface RTCIceServer {
343
+ urls: string | string[];
344
+ username?: string;
345
+ credential?: string;
148
346
  }
149
347
 
150
- export class RTCPeerConnectionIceEvent extends Event {
151
- constructor(type: string, eventInitDict?: RTCPeerConnectionIceEventInit);
152
- readonly candidate: RTCIceCandidate | null;
153
- readonly url: string | null;
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 RTCPeerConnectionEventMap {
157
- connectionstatechange: Event;
158
- datachannel: RTCDataChannelEvent;
159
- icecandidate: RTCPeerConnectionIceEvent;
160
- icecandidateerror: Event;
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, factory?: NativePeerConnectionFactory);
169
-
170
- readonly signalingState: RTCSignalingState;
171
- readonly iceGatheringState: RTCIceGatheringState;
172
- readonly iceConnectionState: RTCIceConnectionState;
173
- readonly connectionState: RTCPeerConnectionState;
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
- createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescription>;
182
- createAnswer(options?: RTCAnswerOptions): Promise<RTCSessionDescription>;
183
- setLocalDescription(description: RTCSessionDescriptionInit): Promise<void>;
184
- setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>;
185
- addIceCandidate(candidate?: RTCIceCandidateInit | null): Promise<void>;
186
- createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel;
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
- getStats(): Promise<any>;
191
-
192
- on<K extends keyof RTCPeerConnectionEventMap>(event: K, listener: (ev: RTCPeerConnectionEventMap[K]) => void): this;
193
- once<K extends keyof RTCPeerConnectionEventMap>(event: K, listener: (ev: RTCPeerConnectionEventMap[K]) => void): this;
194
- off<K extends keyof RTCPeerConnectionEventMap>(event: K, listener: (ev: RTCPeerConnectionEventMap[K]) => void): this;
195
- emit<K extends keyof RTCPeerConnectionEventMap>(event: K, ...args: any[]): boolean;
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
- export class RTCErrorEvent extends Event {
209
- constructor(type: string, eventInitDict: RTCErrorEventInit);
210
- readonly error: RTCError;
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
- * NodeRTC - DataChannel-only WebRTC implementation for Node.js
3
- * Ported from Chromium's PeerConnection implementation
2
+ * @fileoverview node-rtc-connection - WebRTC DataChannel implementation for Node.js
4
3
  *
5
- * This is a simplified implementation focusing on DataChannel functionality.
6
- * It does not include media stream support (audio/video).
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
- const RTCPeerConnection = require('./RTCPeerConnection');
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
- // Create a singleton factory instance
19
- const defaultFactory = new NativePeerConnectionFactory();
21
+ // Foundation Layer
22
+ const ByteBufferQueue = require('./foundation/ByteBufferQueue');
23
+ const RTCError = require('./foundation/RTCError');
20
24
 
21
- /**
22
- * Create a new RTCPeerConnection with the default factory
23
- * @param {Object} configuration - RTCConfiguration
24
- * @returns {RTCPeerConnection}
25
- */
26
- function createPeerConnection(configuration) {
27
- return new RTCPeerConnection(configuration, defaultFactory);
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
- * Create a custom RTCPeerConnection with a specific factory
32
- * @param {Object} configuration - RTCConfiguration
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
- // Main API
42
- RTCPeerConnection,
43
- RTCConnection: RTCPeerConnection, // Alias for convenience
44
- createPeerConnection,
45
- createPeerConnectionWithFactory,
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
- // Classes
77
+ // DataChannel
48
78
  RTCDataChannel,
79
+ RTCDataChannelState,
80
+
81
+ // SDP
49
82
  RTCSessionDescription,
50
- RTCIceCandidate,
51
- RTCDataChannelEvent,
52
- RTCPeerConnectionIceEvent,
53
- RTCError,
54
- RTCErrorEvent,
83
+ RTCSdpType,
84
+
85
+ // PeerConnection
86
+ RTCPeerConnection,
87
+ RTCSignalingState,
88
+ RTCPeerConnectionState,
55
89
 
56
- // Factory
57
- NativePeerConnectionFactory,
58
- defaultFactory
90
+ // Version
91
+ version: require('../package.json').version
59
92
  };