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 +46 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +46 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ICEGatherer.js +13 -3
- package/src/NativePeerConnectionFactory.js +33 -1
package/dist/index.mjs
CHANGED
|
@@ -1618,21 +1618,27 @@ function requireICEGatherer () {
|
|
|
1618
1618
|
const candidates = [];
|
|
1619
1619
|
|
|
1620
1620
|
if (this.turnServers.length === 0) {
|
|
1621
|
+
console.log('[ICEGatherer] No TURN servers configured');
|
|
1621
1622
|
return candidates;
|
|
1622
1623
|
}
|
|
1623
1624
|
|
|
1625
|
+
console.log(`[ICEGatherer] Querying ${this.turnServers.length} TURN server(s) for relay candidates...`);
|
|
1626
|
+
|
|
1624
1627
|
const turnPromises = [];
|
|
1625
1628
|
|
|
1626
1629
|
// Try TURN servers
|
|
1627
1630
|
for (const turnConfig of this.turnServers) {
|
|
1628
1631
|
const promise = this._queryTURNServer(turnConfig, localPort)
|
|
1629
|
-
.catch(err =>
|
|
1632
|
+
.catch(err => {
|
|
1633
|
+
console.warn(`[ICEGatherer] TURN query failed: ${err.message}`);
|
|
1634
|
+
return null;
|
|
1635
|
+
});
|
|
1630
1636
|
turnPromises.push(promise);
|
|
1631
1637
|
}
|
|
1632
1638
|
|
|
1633
|
-
// Wait for first successful response
|
|
1639
|
+
// Wait for first successful response or timeout
|
|
1634
1640
|
const results = await Promise.race([
|
|
1635
|
-
|
|
1641
|
+
...turnPromises,
|
|
1636
1642
|
new Promise(resolve => setTimeout(() => resolve(null), this.gatherTimeout))
|
|
1637
1643
|
]);
|
|
1638
1644
|
|
|
@@ -1642,6 +1648,8 @@ function requireICEGatherer () {
|
|
|
1642
1648
|
|
|
1643
1649
|
const localIp = this._getLocalIPForRemote();
|
|
1644
1650
|
|
|
1651
|
+
console.log(`[ICEGatherer] Got TURN relay: ${results.relayedAddress}:${results.relayedPort}`);
|
|
1652
|
+
|
|
1645
1653
|
candidates.push({
|
|
1646
1654
|
candidate: `candidate:${foundation} 1 udp ${priority} ${results.relayedAddress} ${results.relayedPort} typ relay raddr ${localIp} rport ${localPort}`,
|
|
1647
1655
|
sdpMLineIndex: 0,
|
|
@@ -1657,6 +1665,8 @@ function requireICEGatherer () {
|
|
|
1657
1665
|
relatedAddress: localIp,
|
|
1658
1666
|
relatedPort: localPort
|
|
1659
1667
|
});
|
|
1668
|
+
} else {
|
|
1669
|
+
console.log('[ICEGatherer] No relay candidates obtained from TURN servers');
|
|
1660
1670
|
}
|
|
1661
1671
|
|
|
1662
1672
|
return candidates;
|
|
@@ -2393,7 +2403,8 @@ function requireNativePeerConnectionFactory () {
|
|
|
2393
2403
|
this._useEncryption = this._configuration.encryption === true; // Disabled by default
|
|
2394
2404
|
this._useUDP = this._configuration.transport === 'udp';
|
|
2395
2405
|
this._iceGatherer = new ICEGatherer({
|
|
2396
|
-
stunServers: this._extractSTUNServers(this._configuration)
|
|
2406
|
+
stunServers: this._extractSTUNServers(this._configuration),
|
|
2407
|
+
turnServers: this._extractTURNServers(this._configuration)
|
|
2397
2408
|
});
|
|
2398
2409
|
this._secureConnection = null;
|
|
2399
2410
|
this._udpTransport = null;
|
|
@@ -2430,6 +2441,37 @@ function requireNativePeerConnectionFactory () {
|
|
|
2430
2441
|
return stunServers.length > 0 ? stunServers : undefined;
|
|
2431
2442
|
}
|
|
2432
2443
|
|
|
2444
|
+
/**
|
|
2445
|
+
* Extract TURN servers from configuration
|
|
2446
|
+
* @private
|
|
2447
|
+
*/
|
|
2448
|
+
_extractTURNServers(config) {
|
|
2449
|
+
const turnServers = [];
|
|
2450
|
+
|
|
2451
|
+
if (config.iceServers) {
|
|
2452
|
+
for (const server of config.iceServers) {
|
|
2453
|
+
if (server.urls) {
|
|
2454
|
+
const urls = Array.isArray(server.urls) ? server.urls : [server.urls];
|
|
2455
|
+
for (const url of urls) {
|
|
2456
|
+
if (url.startsWith('turn:')) {
|
|
2457
|
+
turnServers.push({
|
|
2458
|
+
urls: url,
|
|
2459
|
+
username: server.username,
|
|
2460
|
+
credential: server.credential
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
if (turnServers.length > 0) {
|
|
2469
|
+
console.log(`[NativePeerConnection] Configured ${turnServers.length} TURN server(s)`);
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
return turnServers;
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2433
2475
|
/**
|
|
2434
2476
|
* Create an offer
|
|
2435
2477
|
* @param {Object} options
|