node-rtc-connection 1.0.7 → 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/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