node-rtc-connection 1.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 nmhung1210
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,427 @@
1
+ # NodeRTC - WebRTC DataChannels for Node.js
2
+
3
+ [![npm version](https://badge.fury.io/js/nodertc.svg)](https://www.npmjs.com/package/nodertc)
4
+ [![Node.js CI](https://github.com/nmhung1210/nodertc/workflows/Test/badge.svg)](https://github.com/nmhung1210/nodertc/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ A production-ready WebRTC DataChannel implementation for Node.js with **real networking**, **STUN/TURN support**, **MESSAGE-INTEGRITY authentication**, and **optional encryption**. Built with pure Node.js - no native dependencies required.
8
+
9
+ ## Overview
10
+
11
+ NodeRTC provides WebRTC-style peer-to-peer data connections using Node.js built-in modules. It supports NAT traversal via STUN/TURN servers with full RFC 5766 MESSAGE-INTEGRITY authentication, optional TLS encryption, and works across the internet for most network configurations.
12
+
13
+ ## Features
14
+
15
+ - ✅ **RTCPeerConnection** - Full peer connection lifecycle
16
+ - ✅ **RTCDataChannel** - Bidirectional data channels
17
+ - ✅ **STUN Support** - NAT traversal with public STUN servers
18
+ - ✅ **TURN Support** - Relay through TURN servers (RFC 5766)
19
+ - ✅ **MESSAGE-INTEGRITY** - Full authentication support for TURN
20
+ - ✅ **ICE Candidates** - Host, server reflexive, and relay candidates
21
+ - ✅ **TLS Encryption** - Optional secure connections
22
+ - ✅ **Real Networking** - TCP/UDP with actual peer-to-peer communication
23
+ - ✅ **Event-based API** - Built on Node.js EventEmitter
24
+ - ✅ **Zero Dependencies** - Pure Node.js, no native modules
25
+ - ✅ **Docker TURN Server** - Included for testing and development
26
+ - ❌ **No Media Support** - DataChannel only (no audio/video)
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install nodertc
32
+ ```
33
+
34
+ ## Quick Start
35
+
36
+ ### Basic Usage
37
+
38
+ ```javascript
39
+ const { createPeerConnection } = require('nodertc');
40
+
41
+ // Create peer connection
42
+ const pc = createPeerConnection();
43
+
44
+ // Create a data channel
45
+ const channel = pc.createDataChannel('myChannel');
46
+
47
+ channel.on('open', () => {
48
+ console.log('DataChannel opened');
49
+ channel.send('Hello, peer!');
50
+ });
51
+
52
+ channel.on('message', (event) => {
53
+ console.log('Received:', event.data.toString());
54
+ });
55
+
56
+ // Handle ICE candidates
57
+ pc.on('icecandidate', (event) => {
58
+ if (event.candidate) {
59
+ // Send to remote peer via signaling
60
+ }
61
+ });
62
+
63
+ // Create and set local description
64
+ const offer = await pc.createOffer();
65
+ await pc.setLocalDescription(offer);
66
+ ```
67
+
68
+ ### With STUN and TURN (Recommended)
69
+
70
+ ```javascript
71
+ const { createPeerConnection } = require('nodertc');
72
+
73
+ // Configuration with STUN and TURN
74
+ const config = {
75
+ iceServers: [
76
+ { urls: 'stun:stun.l.google.com:19302' },
77
+ {
78
+ urls: 'turn:turn.example.com:3478',
79
+ username: 'username',
80
+ credential: 'password'
81
+ }
82
+ ],
83
+ encryption: false, // Optional TLS encryption
84
+ transport: 'tcp' // Use TCP (or 'udp')
85
+ };
86
+
87
+ // Create peer connection
88
+ const pc = createPeerConnection(config);
89
+
90
+ // Rest is the same as basic usage...
91
+
92
+ channel.on('message', (event) => {
93
+ console.log('Received:', event.data.toString());
94
+ });
95
+
96
+ // ICE candidates (includes STUN reflexive candidates)
97
+ pc.on('icecandidate', (event) => {
98
+ if (event.candidate) {
99
+ // Send to remote peer via signaling
100
+ console.log('Candidate:', event.candidate.candidate);
101
+ }
102
+ });
103
+ ```
104
+
105
+ See [examples/with-stun-encryption.js](examples/with-stun-encryption.js) for a complete working example.
106
+
107
+ ## Usage
108
+
109
+ ### Basic Example
110
+
111
+ ```javascript
112
+ const { createPeerConnection } = require('./src');
113
+
114
+ // Create peer connection with STUN server
115
+ const pc = createPeerConnection({
116
+ iceServers: [
117
+ { urls: 'stun:stun.l.google.com:19302' }
118
+ ]
119
+ });
120
+
121
+ // Create a data channel
122
+ const channel = pc.createDataChannel('myChannel', {
123
+ ordered: true
124
+ });
125
+
126
+ // Handle channel events
127
+ channel.on('open', () => {
128
+ console.log('DataChannel opened');
129
+ channel.send('Hello, peer!');
130
+ });
131
+
132
+ channel.on('message', (event) => {
133
+ console.log('Received:', event.data);
134
+ });
135
+
136
+ channel.on('close', () => {
137
+ console.log('DataChannel closed');
138
+ });
139
+
140
+ // Handle peer connection events
141
+ pc.on('icecandidate', (event) => {
142
+ if (event.candidate) {
143
+ // Send candidate to remote peer via signaling
144
+ console.log('ICE candidate:', event.candidate);
145
+ }
146
+ });
147
+
148
+ pc.on('datachannel', (event) => {
149
+ // Handle incoming data channel from remote peer
150
+ const remoteChannel = event.channel;
151
+ console.log('Remote channel opened:', remoteChannel.label);
152
+ });
153
+
154
+ // Create and send offer
155
+ pc.createOffer()
156
+ .then(offer => pc.setLocalDescription(offer))
157
+ .then(() => {
158
+ // Send offer to remote peer via signaling
159
+ console.log('Offer created:', pc.localDescription);
160
+ });
161
+ ```
162
+
163
+ ### Complete Signaling Example
164
+
165
+ ```javascript
166
+ const { createPeerConnection } = require('./src');
167
+
168
+ // Peer 1 (Offerer)
169
+ const pc1 = createPeerConnection({
170
+ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
171
+ });
172
+
173
+ // Peer 2 (Answerer)
174
+ const pc2 = createPeerConnection({
175
+ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
176
+ });
177
+
178
+ // Exchange ICE candidates
179
+ pc1.on('icecandidate', (event) => {
180
+ if (event.candidate) {
181
+ pc2.addIceCandidate(event.candidate);
182
+ }
183
+ });
184
+
185
+ pc2.on('icecandidate', (event) => {
186
+ if (event.candidate) {
187
+ pc1.addIceCandidate(event.candidate);
188
+ }
189
+ });
190
+
191
+ // Handle incoming data channel on peer 2
192
+ pc2.on('datachannel', (event) => {
193
+ const channel = event.channel;
194
+ channel.on('message', (event) => {
195
+ console.log('Peer 2 received:', event.data);
196
+ channel.send('Hello from Peer 2!');
197
+ });
198
+ });
199
+
200
+ // Create data channel on peer 1
201
+ const channel = pc1.createDataChannel('chat');
202
+
203
+ channel.on('open', () => {
204
+ console.log('Channel opened');
205
+ channel.send('Hello from Peer 1!');
206
+ });
207
+
208
+ channel.on('message', (event) => {
209
+ console.log('Peer 1 received:', event.data);
210
+ });
211
+
212
+ // Start signaling
213
+ async function connect() {
214
+ // Create offer
215
+ const offer = await pc1.createOffer();
216
+ await pc1.setLocalDescription(offer);
217
+
218
+ // Set remote description on peer 2
219
+ await pc2.setRemoteDescription(offer);
220
+
221
+ // Create answer
222
+ const answer = await pc2.createAnswer();
223
+ await pc2.setLocalDescription(answer);
224
+
225
+ // Set remote description on peer 1
226
+ await pc1.setRemoteDescription(answer);
227
+ }
228
+
229
+ connect();
230
+ ```
231
+
232
+ ## API Reference
233
+
234
+ ### RTCPeerConnection
235
+
236
+ #### Constructor
237
+ ```javascript
238
+ new RTCPeerConnection(configuration, nativePeerConnectionFactory)
239
+ ```
240
+
241
+ #### Properties
242
+ - `signalingState` - Current signaling state
243
+ - `iceGatheringState` - Current ICE gathering state
244
+ - `iceConnectionState` - Current ICE connection state
245
+ - `connectionState` - Current connection state
246
+ - `localDescription` - Local session description
247
+ - `remoteDescription` - Remote session description
248
+
249
+ #### Methods
250
+ - `createOffer(options)` - Create an SDP offer
251
+ - `createAnswer(options)` - Create an SDP answer
252
+ - `setLocalDescription(description)` - Set local description
253
+ - `setRemoteDescription(description)` - Set remote description
254
+ - `addIceCandidate(candidate)` - Add an ICE candidate
255
+ - `createDataChannel(label, options)` - Create a data channel
256
+ - `getConfiguration()` - Get current configuration
257
+ - `setConfiguration(configuration)` - Update configuration
258
+ - `close()` - Close the peer connection
259
+ - `getStats()` - Get connection statistics
260
+
261
+ #### Events
262
+ - `signalingstatechange` - Signaling state changed
263
+ - `iceconnectionstatechange` - ICE connection state changed
264
+ - `icegatheringstatechange` - ICE gathering state changed
265
+ - `connectionstatechange` - Connection state changed
266
+ - `icecandidate` - New ICE candidate available
267
+ - `datachannel` - Remote data channel opened
268
+ - `negotiationneeded` - Negotiation needed
269
+
270
+ ### RTCDataChannel
271
+
272
+ #### Properties
273
+ - `label` - Channel label
274
+ - `ordered` - Whether messages are ordered
275
+ - `maxPacketLifeTime` - Maximum packet lifetime
276
+ - `maxRetransmits` - Maximum retransmits
277
+ - `protocol` - Subprotocol name
278
+ - `negotiated` - Whether channel was negotiated
279
+ - `id` - Channel ID
280
+ - `readyState` - Current state: 'connecting', 'open', 'closing', 'closed'
281
+ - `bufferedAmount` - Bytes queued to send
282
+ - `bufferedAmountLowThreshold` - Threshold for bufferedamountlow event
283
+ - `binaryType` - Binary data format: 'arraybuffer' or 'blob'
284
+
285
+ #### Methods
286
+ - `send(data)` - Send data (string, ArrayBuffer, or ArrayBufferView)
287
+ - `close()` - Close the channel
288
+
289
+ #### Events
290
+ - `open` - Channel opened
291
+ - `close` - Channel closed
292
+ - `message` - Message received
293
+ - `error` - Error occurred
294
+ - `bufferedamountlow` - Buffered amount dropped below threshold
295
+
296
+ ## Testing
297
+
298
+ NodeRTC includes comprehensive unit tests covering all components:
299
+
300
+ ```bash
301
+ # Run all unit tests (fast, ~500ms)
302
+ npm test
303
+
304
+ # Run tests in watch mode
305
+ npm run test:watch
306
+
307
+ # Run integration tests (slower, uses real networking)
308
+ npm run test:integration
309
+
310
+ # Run all tests including integration
311
+ npm run test:all
312
+ ```
313
+
314
+ **Test Coverage**: 96 unit tests with 100% pass rate. See [TEST_COVERAGE.md](TEST_COVERAGE.md) for detailed coverage information.
315
+
316
+ ## Implementation Notes
317
+
318
+ ### Current Implementation
319
+
320
+ This implementation uses **real Node.js networking** via the `net` package for peer-to-peer TCP connections:
321
+
322
+ - ✅ **Real TCP connections** between peers
323
+ - ✅ **Actual data transmission** over sockets
324
+ - ✅ **Real SDP generation** with network addresses
325
+ - ✅ **Working ICE candidates** with local IP addresses
326
+ - ✅ **Bidirectional messaging** between data channels
327
+ - ✅ **Connection lifecycle** management
328
+
329
+ The `NativePeerConnectionFactory` creates TCP servers and clients to establish peer-to-peer connections. Data channels transmit messages over these TCP connections using a simple framing protocol.
330
+
331
+ ### How It Works
332
+
333
+ 1. **Offer/Answer Exchange**: Peers exchange SDP containing their IP address and port
334
+ 2. **TCP Server**: Each peer creates a TCP server listening on a random port
335
+ 3. **Connection**: The answerer connects to the offerer's TCP server
336
+ 4. **Data Channel Protocol**: Messages are framed with length + channel label + data
337
+ 5. **Bidirectional Communication**: Both peers can send and receive on the established socket
338
+
339
+ ### Example Output
340
+
341
+ ```bash
342
+ $ node examples/real-networking.js
343
+
344
+ ✓ PC1: Data channel opened!
345
+ ✓ PC2: Data channel opened!
346
+
347
+ PC1: Sending first message...
348
+ 📨 PC2 received: Hello from Peer 1!
349
+ PC2: Sending reply...
350
+ 📨 PC1 received: Hello from Peer 2! Nice to meet you.
351
+ ```
352
+
353
+ ## Development & Contributing
354
+
355
+ ### Setup
356
+
357
+ ```bash
358
+ git clone https://github.com/nmhung1210/nodertc.git
359
+ cd nodertc
360
+ npm install
361
+ ```
362
+
363
+ ### Testing
364
+
365
+ ```bash
366
+ # Run all tests
367
+ npm test
368
+
369
+ # Run specific test suites
370
+ npm run test:stun # STUN tests
371
+ npm run test:turn # TURN tests
372
+ npm run test:integration # Integration tests
373
+ ```
374
+
375
+ ### Building
376
+
377
+ ```bash
378
+ npm run build
379
+ ```
380
+
381
+ This creates CommonJS and ES Module bundles in `dist/`.
382
+
383
+ ### CI/CD
384
+
385
+ This project uses GitHub Actions for automated testing and publishing:
386
+
387
+ - **Test Workflow**: Runs on push/PR, tests on Node.js 18.x, 20.x, 22.x
388
+ - **Publish Workflow**: Triggers on version tags, automatically publishes to NPM
389
+
390
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed publishing instructions.
391
+
392
+ ## Differences from Browser WebRTC
393
+
394
+ ### Not Included (DataChannel-only focus)
395
+ - ❌ MediaStream / MediaStreamTrack
396
+ - ❌ getUserMedia
397
+ - ❌ RTCRtpSender / RTCRtpReceiver
398
+ - ❌ RTCRtpTransceiver
399
+ - ❌ Audio/Video codecs
400
+ - ❌ RTCDTMFSender
401
+ - ❌ Media constraints
402
+
403
+ ### Simplified
404
+ - Event handling uses Node.js EventEmitter instead of DOM events
405
+ - No dependency on browser APIs
406
+ - Synchronous where possible (async only for native operations)
407
+
408
+ ## Contributing
409
+
410
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
411
+
412
+ ## License
413
+
414
+ MIT License - see [LICENSE](LICENSE) file for details.
415
+
416
+ ## Credits
417
+
418
+ Ported from Chromium's WebRTC implementation:
419
+ - Original source: `third_party/blink/renderer/modules/peerconnection/`
420
+ - Copyright (C) 2012 Google Inc.
421
+
422
+ ## Links
423
+
424
+ - [NPM Package](https://www.npmjs.com/package/nodertc)
425
+ - [GitHub Repository](https://github.com/nmhung1210/nodertc)
426
+ - [Issues](https://github.com/nmhung1210/nodertc/issues)
427
+ - [Contributing Guide](CONTRIBUTING.md)
package/dist/index.cjs ADDED
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * NodeRTC - DataChannel-only WebRTC implementation for Node.js
5
+ * Ported from Chromium's PeerConnection implementation
6
+ *
7
+ * This is a simplified implementation focusing on DataChannel functionality.
8
+ * It does not include media stream support (audio/video).
9
+ */
10
+
11
+ const RTCPeerConnection = require('./RTCPeerConnection');
12
+ const RTCDataChannel = require('./RTCDataChannel');
13
+ const RTCSessionDescription = require('./RTCSessionDescription');
14
+ const RTCIceCandidate = require('./RTCIceCandidate');
15
+ const RTCDataChannelEvent = require('./RTCDataChannelEvent');
16
+ const RTCPeerConnectionIceEvent = require('./RTCPeerConnectionIceEvent');
17
+ const { RTCError, RTCErrorEvent } = require('./RTCError');
18
+ const NativePeerConnectionFactory = require('./NativePeerConnectionFactory');
19
+
20
+ // Create a singleton factory instance
21
+ const defaultFactory = new NativePeerConnectionFactory();
22
+
23
+ /**
24
+ * Create a new RTCPeerConnection with the default factory
25
+ * @param {Object} configuration - RTCConfiguration
26
+ * @returns {RTCPeerConnection}
27
+ */
28
+ function createPeerConnection(configuration) {
29
+ return new RTCPeerConnection(configuration, defaultFactory);
30
+ }
31
+
32
+ /**
33
+ * Create a custom RTCPeerConnection with a specific factory
34
+ * @param {Object} configuration - RTCConfiguration
35
+ * @param {NativePeerConnectionFactory} factory - Custom factory
36
+ * @returns {RTCPeerConnection}
37
+ */
38
+ function createPeerConnectionWithFactory(configuration, factory) {
39
+ return new RTCPeerConnection(configuration, factory);
40
+ }
41
+
42
+ module.exports = {
43
+ // Main API
44
+ RTCPeerConnection,
45
+ createPeerConnection,
46
+ createPeerConnectionWithFactory,
47
+
48
+ // Classes
49
+ RTCDataChannel,
50
+ RTCSessionDescription,
51
+ RTCIceCandidate,
52
+ RTCDataChannelEvent,
53
+ RTCPeerConnectionIceEvent,
54
+ RTCError,
55
+ RTCErrorEvent,
56
+
57
+ // Factory
58
+ NativePeerConnectionFactory,
59
+ defaultFactory
60
+ };
61
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["/**\n * NodeRTC - DataChannel-only WebRTC implementation for Node.js\n * Ported from Chromium's PeerConnection implementation\n * \n * This is a simplified implementation focusing on DataChannel functionality.\n * It does not include media stream support (audio/video).\n */\n\nconst RTCPeerConnection = require('./RTCPeerConnection');\nconst RTCDataChannel = require('./RTCDataChannel');\nconst RTCSessionDescription = require('./RTCSessionDescription');\nconst RTCIceCandidate = require('./RTCIceCandidate');\nconst RTCDataChannelEvent = require('./RTCDataChannelEvent');\nconst RTCPeerConnectionIceEvent = require('./RTCPeerConnectionIceEvent');\nconst { RTCError, RTCErrorEvent } = require('./RTCError');\nconst NativePeerConnectionFactory = require('./NativePeerConnectionFactory');\n\n// Create a singleton factory instance\nconst defaultFactory = new NativePeerConnectionFactory();\n\n/**\n * Create a new RTCPeerConnection with the default factory\n * @param {Object} configuration - RTCConfiguration\n * @returns {RTCPeerConnection}\n */\nfunction createPeerConnection(configuration) {\n return new RTCPeerConnection(configuration, defaultFactory);\n}\n\n/**\n * Create a custom RTCPeerConnection with a specific factory\n * @param {Object} configuration - RTCConfiguration\n * @param {NativePeerConnectionFactory} factory - Custom factory\n * @returns {RTCPeerConnection}\n */\nfunction createPeerConnectionWithFactory(configuration, factory) {\n return new RTCPeerConnection(configuration, factory);\n}\n\nmodule.exports = {\n // Main API\n RTCPeerConnection,\n createPeerConnection,\n createPeerConnectionWithFactory,\n \n // Classes\n RTCDataChannel,\n RTCSessionDescription,\n RTCIceCandidate,\n RTCDataChannelEvent,\n RTCPeerConnectionIceEvent,\n RTCError,\n RTCErrorEvent,\n \n // Factory\n NativePeerConnectionFactory,\n defaultFactory\n};\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;AACxD,MAAM,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC;AAClD,MAAM,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC;AAChE,MAAM,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;AACpD,MAAM,mBAAmB,GAAG,OAAO,CAAC,uBAAuB,CAAC;AAC5D,MAAM,yBAAyB,GAAG,OAAO,CAAC,6BAA6B,CAAC;AACxE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;AACzD,MAAM,2BAA2B,GAAG,OAAO,CAAC,+BAA+B,CAAC;;AAE5E;AACA,MAAM,cAAc,GAAG,IAAI,2BAA2B,EAAE;;AAExD;AACA;AACA;AACA;AACA;AACA,SAAS,oBAAoB,CAAC,aAAa,EAAE;AAC7C,EAAE,OAAO,IAAI,iBAAiB,CAAC,aAAa,EAAE,cAAc,CAAC;AAC7D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,+BAA+B,CAAC,aAAa,EAAE,OAAO,EAAE;AACjE,EAAE,OAAO,IAAI,iBAAiB,CAAC,aAAa,EAAE,OAAO,CAAC;AACtD;;AAEA,MAAM,CAAC,OAAO,GAAG;AACjB;AACA,EAAE,iBAAiB;AACnB,EAAE,oBAAoB;AACtB,EAAE,+BAA+B;AACjC;AACA;AACA,EAAE,cAAc;AAChB,EAAE,qBAAqB;AACvB,EAAE,eAAe;AACjB,EAAE,mBAAmB;AACrB,EAAE,yBAAyB;AAC3B,EAAE,QAAQ;AACV,EAAE,aAAa;AACf;AACA;AACA,EAAE,2BAA2B;AAC7B,EAAE;AACF,CAAC;;"}
package/dist/index.mjs ADDED
@@ -0,0 +1,59 @@
1
+ /**
2
+ * NodeRTC - DataChannel-only WebRTC implementation for Node.js
3
+ * Ported from Chromium's PeerConnection implementation
4
+ *
5
+ * This is a simplified implementation focusing on DataChannel functionality.
6
+ * It does not include media stream support (audio/video).
7
+ */
8
+
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');
17
+
18
+ // Create a singleton factory instance
19
+ const defaultFactory = new NativePeerConnectionFactory();
20
+
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
+ }
29
+
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
+ }
39
+
40
+ module.exports = {
41
+ // Main API
42
+ RTCPeerConnection,
43
+ createPeerConnection,
44
+ createPeerConnectionWithFactory,
45
+
46
+ // Classes
47
+ RTCDataChannel,
48
+ RTCSessionDescription,
49
+ RTCIceCandidate,
50
+ RTCDataChannelEvent,
51
+ RTCPeerConnectionIceEvent,
52
+ RTCError,
53
+ RTCErrorEvent,
54
+
55
+ // Factory
56
+ NativePeerConnectionFactory,
57
+ defaultFactory
58
+ };
59
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.js"],"sourcesContent":["/**\n * NodeRTC - DataChannel-only WebRTC implementation for Node.js\n * Ported from Chromium's PeerConnection implementation\n * \n * This is a simplified implementation focusing on DataChannel functionality.\n * It does not include media stream support (audio/video).\n */\n\nconst RTCPeerConnection = require('./RTCPeerConnection');\nconst RTCDataChannel = require('./RTCDataChannel');\nconst RTCSessionDescription = require('./RTCSessionDescription');\nconst RTCIceCandidate = require('./RTCIceCandidate');\nconst RTCDataChannelEvent = require('./RTCDataChannelEvent');\nconst RTCPeerConnectionIceEvent = require('./RTCPeerConnectionIceEvent');\nconst { RTCError, RTCErrorEvent } = require('./RTCError');\nconst NativePeerConnectionFactory = require('./NativePeerConnectionFactory');\n\n// Create a singleton factory instance\nconst defaultFactory = new NativePeerConnectionFactory();\n\n/**\n * Create a new RTCPeerConnection with the default factory\n * @param {Object} configuration - RTCConfiguration\n * @returns {RTCPeerConnection}\n */\nfunction createPeerConnection(configuration) {\n return new RTCPeerConnection(configuration, defaultFactory);\n}\n\n/**\n * Create a custom RTCPeerConnection with a specific factory\n * @param {Object} configuration - RTCConfiguration\n * @param {NativePeerConnectionFactory} factory - Custom factory\n * @returns {RTCPeerConnection}\n */\nfunction createPeerConnectionWithFactory(configuration, factory) {\n return new RTCPeerConnection(configuration, factory);\n}\n\nmodule.exports = {\n // Main API\n RTCPeerConnection,\n createPeerConnection,\n createPeerConnectionWithFactory,\n \n // Classes\n RTCDataChannel,\n RTCSessionDescription,\n RTCIceCandidate,\n RTCDataChannelEvent,\n RTCPeerConnectionIceEvent,\n RTCError,\n RTCErrorEvent,\n \n // Factory\n NativePeerConnectionFactory,\n defaultFactory\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;AACxD,MAAM,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC;AAClD,MAAM,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,CAAC;AAChE,MAAM,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC;AACpD,MAAM,mBAAmB,GAAG,OAAO,CAAC,uBAAuB,CAAC;AAC5D,MAAM,yBAAyB,GAAG,OAAO,CAAC,6BAA6B,CAAC;AACxE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;AACzD,MAAM,2BAA2B,GAAG,OAAO,CAAC,+BAA+B,CAAC;;AAE5E;AACA,MAAM,cAAc,GAAG,IAAI,2BAA2B,EAAE;;AAExD;AACA;AACA;AACA;AACA;AACA,SAAS,oBAAoB,CAAC,aAAa,EAAE;AAC7C,EAAE,OAAO,IAAI,iBAAiB,CAAC,aAAa,EAAE,cAAc,CAAC;AAC7D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,+BAA+B,CAAC,aAAa,EAAE,OAAO,EAAE;AACjE,EAAE,OAAO,IAAI,iBAAiB,CAAC,aAAa,EAAE,OAAO,CAAC;AACtD;;AAEA,MAAM,CAAC,OAAO,GAAG;AACjB;AACA,EAAE,iBAAiB;AACnB,EAAE,oBAAoB;AACtB,EAAE,+BAA+B;AACjC;AACA;AACA,EAAE,cAAc;AAChB,EAAE,qBAAqB;AACvB,EAAE,eAAe;AACjB,EAAE,mBAAmB;AACrB,EAAE,yBAAyB;AAC3B,EAAE,QAAQ;AACV,EAAE,aAAa;AACf;AACA;AACA,EAAE,2BAA2B;AAC7B,EAAE;AACF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "node-rtc-connection",
3
+ "version": "1.0.3",
4
+ "description": "WebRTC DataChannel implementation for Node.js with STUN, TURN, NAT traversal, and encryption. Pure Node.js, no native dependencies.",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./dist/index.cjs",
10
+ "import": "./dist/index.mjs"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "src",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "scripts": {
20
+ "build": "rollup -c",
21
+ "prepublishOnly": "npm run build && npm test",
22
+ "test": "node test/run-all-tests.js",
23
+ "test:watch": "node --test --watch test/*.test.js",
24
+ "test:unit": "SKIP_INTEGRATION=1 node --test test/*.test.js",
25
+ "test:integration": "node --test test/integration.test.js",
26
+ "test:all": "SKIP_INTEGRATION=0 node test/run-all-tests.js",
27
+ "test:stun": "node --test test/STUN.test.js",
28
+ "test:turn": "node --test test/TURN.test.js",
29
+ "test:turn-integration": "node --test test/turn-integration.test.js",
30
+ "test:turn-all": "node --test test/TURN.test.js test/turn-integration.test.js",
31
+ "example": "node examples/real-networking.js",
32
+ "example:simple": "node examples/simple-datachannel.js",
33
+ "example:stun": "node examples/with-stun-encryption.js",
34
+ "example:turn": "node examples/with-turn-relay.js",
35
+ "release:patch": "npm version patch && git push && git push --tags",
36
+ "release:minor": "npm version minor && git push && git push --tags",
37
+ "release:major": "npm version major && git push && git push --tags"
38
+ },
39
+ "keywords": [
40
+ "webrtc",
41
+ "datachannel",
42
+ "peer-connection",
43
+ "rtc",
44
+ "p2p",
45
+ "real-time",
46
+ "stun",
47
+ "turn",
48
+ "nat-traversal",
49
+ "ice",
50
+ "encryption",
51
+ "tls",
52
+ "dtls",
53
+ "relay",
54
+ "peer-to-peer"
55
+ ],
56
+ "author": "nmhung1210",
57
+ "license": "MIT",
58
+ "type": "commonjs",
59
+ "engines": {
60
+ "node": ">=14.0.0"
61
+ },
62
+ "devDependencies": {
63
+ "rollup": "^4.54.0"
64
+ },
65
+ "repository": {
66
+ "type": "git",
67
+ "url": "git+https://github.com/nmhung1210/nodertc.git"
68
+ },
69
+ "bugs": {
70
+ "url": "https://github.com/nmhung1210/nodertc/issues"
71
+ },
72
+ "homepage": "https://github.com/nmhung1210/nodertc#readme"
73
+ }