node-rtc-connection 1.0.6 → 1.0.8

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 CHANGED
@@ -1,6 +1,6 @@
1
- # NodeRTC - WebRTC DataChannels for Node.js
1
+ # node-rtc-connection - WebRTC DataChannels for Node.js
2
2
 
3
- [![npm version](https://badge.fury.io/js/nodertc.svg)](https://www.npmjs.com/package/nodertc)
3
+ [![npm version](https://badge.fury.io/js/node-rtc-connection.svg)](https://www.npmjs.com/package/node-rtc-connection)
4
4
  [![Node.js CI](https://github.com/nmhung1210/nodertc/workflows/Test/badge.svg)](https://github.com/nmhung1210/nodertc/actions)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
@@ -8,7 +8,7 @@ A production-ready WebRTC DataChannel implementation for Node.js with **real net
8
8
 
9
9
  ## Overview
10
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.
11
+ node-rtc-connection 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
12
 
13
13
  ## Features
14
14
 
@@ -28,7 +28,7 @@ NodeRTC provides WebRTC-style peer-to-peer data connections using Node.js built-
28
28
  ## Installation
29
29
 
30
30
  ```bash
31
- npm install nodertc
31
+ npm install node-rtc-connection
32
32
  ```
33
33
 
34
34
  ## Quick Start
@@ -36,7 +36,7 @@ npm install nodertc
36
36
  ### Basic Usage
37
37
 
38
38
  ```javascript
39
- const { createPeerConnection } = require('nodertc');
39
+ const { createPeerConnection } = require('node-rtc-connection');
40
40
 
41
41
  // Create peer connection
42
42
  const pc = createPeerConnection();
@@ -68,7 +68,7 @@ await pc.setLocalDescription(offer);
68
68
  ### With STUN and TURN (Recommended)
69
69
 
70
70
  ```javascript
71
- const { createPeerConnection } = require('nodertc');
71
+ const { createPeerConnection } = require('node-rtc-connection');
72
72
 
73
73
  // Configuration with STUN and TURN
74
74
  const config = {
@@ -295,7 +295,7 @@ new RTCPeerConnection(configuration, nativePeerConnectionFactory)
295
295
 
296
296
  ## Testing
297
297
 
298
- NodeRTC includes comprehensive unit tests covering all components:
298
+ node-rtc-connection includes comprehensive unit tests covering all components:
299
299
 
300
300
  ```bash
301
301
  # Run all unit tests (fast, ~500ms)
@@ -421,7 +421,7 @@ Ported from Chromium's WebRTC implementation:
421
421
 
422
422
  ## Links
423
423
 
424
- - [NPM Package](https://www.npmjs.com/package/nodertc)
424
+ - [NPM Package](https://www.npmjs.com/package/node-rtc-connection)
425
425
  - [GitHub Repository](https://github.com/nmhung1210/nodertc)
426
426
  - [Issues](https://github.com/nmhung1210/nodertc/issues)
427
427
  - [Contributing Guide](CONTRIBUTING.md)
package/dist/index.cjs CHANGED
@@ -1620,21 +1620,27 @@ function requireICEGatherer () {
1620
1620
  const candidates = [];
1621
1621
 
1622
1622
  if (this.turnServers.length === 0) {
1623
+ console.log('[ICEGatherer] No TURN servers configured');
1623
1624
  return candidates;
1624
1625
  }
1625
1626
 
1627
+ console.log(`[ICEGatherer] Querying ${this.turnServers.length} TURN server(s) for relay candidates...`);
1628
+
1626
1629
  const turnPromises = [];
1627
1630
 
1628
1631
  // Try TURN servers
1629
1632
  for (const turnConfig of this.turnServers) {
1630
1633
  const promise = this._queryTURNServer(turnConfig, localPort)
1631
- .catch(err => null); // Ignore individual failures
1634
+ .catch(err => {
1635
+ console.warn(`[ICEGatherer] TURN query failed: ${err.message}`);
1636
+ return null;
1637
+ });
1632
1638
  turnPromises.push(promise);
1633
1639
  }
1634
1640
 
1635
- // Wait for first successful response
1641
+ // Wait for first successful response or timeout
1636
1642
  const results = await Promise.race([
1637
- Promise.any(turnPromises.filter(p => p)),
1643
+ ...turnPromises,
1638
1644
  new Promise(resolve => setTimeout(() => resolve(null), this.gatherTimeout))
1639
1645
  ]);
1640
1646
 
@@ -1644,6 +1650,8 @@ function requireICEGatherer () {
1644
1650
 
1645
1651
  const localIp = this._getLocalIPForRemote();
1646
1652
 
1653
+ console.log(`[ICEGatherer] Got TURN relay: ${results.relayedAddress}:${results.relayedPort}`);
1654
+
1647
1655
  candidates.push({
1648
1656
  candidate: `candidate:${foundation} 1 udp ${priority} ${results.relayedAddress} ${results.relayedPort} typ relay raddr ${localIp} rport ${localPort}`,
1649
1657
  sdpMLineIndex: 0,
@@ -1659,6 +1667,8 @@ function requireICEGatherer () {
1659
1667
  relatedAddress: localIp,
1660
1668
  relatedPort: localPort
1661
1669
  });
1670
+ } else {
1671
+ console.log('[ICEGatherer] No relay candidates obtained from TURN servers');
1662
1672
  }
1663
1673
 
1664
1674
  return candidates;
@@ -2395,7 +2405,8 @@ function requireNativePeerConnectionFactory () {
2395
2405
  this._useEncryption = this._configuration.encryption === true; // Disabled by default
2396
2406
  this._useUDP = this._configuration.transport === 'udp';
2397
2407
  this._iceGatherer = new ICEGatherer({
2398
- stunServers: this._extractSTUNServers(this._configuration)
2408
+ stunServers: this._extractSTUNServers(this._configuration),
2409
+ turnServers: this._extractTURNServers(this._configuration)
2399
2410
  });
2400
2411
  this._secureConnection = null;
2401
2412
  this._udpTransport = null;
@@ -2432,6 +2443,37 @@ function requireNativePeerConnectionFactory () {
2432
2443
  return stunServers.length > 0 ? stunServers : undefined;
2433
2444
  }
2434
2445
 
2446
+ /**
2447
+ * Extract TURN servers from configuration
2448
+ * @private
2449
+ */
2450
+ _extractTURNServers(config) {
2451
+ const turnServers = [];
2452
+
2453
+ if (config.iceServers) {
2454
+ for (const server of config.iceServers) {
2455
+ if (server.urls) {
2456
+ const urls = Array.isArray(server.urls) ? server.urls : [server.urls];
2457
+ for (const url of urls) {
2458
+ if (url.startsWith('turn:')) {
2459
+ turnServers.push({
2460
+ urls: url,
2461
+ username: server.username,
2462
+ credential: server.credential
2463
+ });
2464
+ }
2465
+ }
2466
+ }
2467
+ }
2468
+ }
2469
+
2470
+ if (turnServers.length > 0) {
2471
+ console.log(`[NativePeerConnection] Configured ${turnServers.length} TURN server(s)`);
2472
+ }
2473
+
2474
+ return turnServers;
2475
+ }
2476
+
2435
2477
  /**
2436
2478
  * Create an offer
2437
2479
  * @param {Object} options