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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-rtc-connection",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "WebRTC DataChannel implementation for Node.js with STUN, TURN, NAT traversal, and encryption. Pure Node.js, no native dependencies.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -187,21 +187,27 @@ class ICEGatherer {
187
187
  const candidates = [];
188
188
 
189
189
  if (this.turnServers.length === 0) {
190
+ console.log('[ICEGatherer] No TURN servers configured');
190
191
  return candidates;
191
192
  }
192
193
 
194
+ console.log(`[ICEGatherer] Querying ${this.turnServers.length} TURN server(s) for relay candidates...`);
195
+
193
196
  const turnPromises = [];
194
197
 
195
198
  // Try TURN servers
196
199
  for (const turnConfig of this.turnServers) {
197
200
  const promise = this._queryTURNServer(turnConfig, localPort)
198
- .catch(err => null); // Ignore individual failures
201
+ .catch(err => {
202
+ console.warn(`[ICEGatherer] TURN query failed: ${err.message}`);
203
+ return null;
204
+ });
199
205
  turnPromises.push(promise);
200
206
  }
201
207
 
202
- // Wait for first successful response
208
+ // Wait for first successful response or timeout
203
209
  const results = await Promise.race([
204
- Promise.any(turnPromises.filter(p => p)),
210
+ ...turnPromises,
205
211
  new Promise(resolve => setTimeout(() => resolve(null), this.gatherTimeout))
206
212
  ]);
207
213
 
@@ -211,6 +217,8 @@ class ICEGatherer {
211
217
 
212
218
  const localIp = this._getLocalIPForRemote();
213
219
 
220
+ console.log(`[ICEGatherer] Got TURN relay: ${results.relayedAddress}:${results.relayedPort}`);
221
+
214
222
  candidates.push({
215
223
  candidate: `candidate:${foundation} 1 udp ${priority} ${results.relayedAddress} ${results.relayedPort} typ relay raddr ${localIp} rport ${localPort}`,
216
224
  sdpMLineIndex: 0,
@@ -226,6 +234,8 @@ class ICEGatherer {
226
234
  relatedAddress: localIp,
227
235
  relatedPort: localPort
228
236
  });
237
+ } else {
238
+ console.log('[ICEGatherer] No relay candidates obtained from TURN servers');
229
239
  }
230
240
 
231
241
  return candidates;
@@ -95,7 +95,8 @@ class NativePeerConnection extends EventEmitter {
95
95
  this._useEncryption = this._configuration.encryption === true; // Disabled by default
96
96
  this._useUDP = this._configuration.transport === 'udp';
97
97
  this._iceGatherer = new ICEGatherer({
98
- stunServers: this._extractSTUNServers(this._configuration)
98
+ stunServers: this._extractSTUNServers(this._configuration),
99
+ turnServers: this._extractTURNServers(this._configuration)
99
100
  });
100
101
  this._secureConnection = null;
101
102
  this._udpTransport = null;
@@ -132,6 +133,37 @@ class NativePeerConnection extends EventEmitter {
132
133
  return stunServers.length > 0 ? stunServers : undefined;
133
134
  }
134
135
 
136
+ /**
137
+ * Extract TURN servers from configuration
138
+ * @private
139
+ */
140
+ _extractTURNServers(config) {
141
+ const turnServers = [];
142
+
143
+ if (config.iceServers) {
144
+ for (const server of config.iceServers) {
145
+ if (server.urls) {
146
+ const urls = Array.isArray(server.urls) ? server.urls : [server.urls];
147
+ for (const url of urls) {
148
+ if (url.startsWith('turn:')) {
149
+ turnServers.push({
150
+ urls: url,
151
+ username: server.username,
152
+ credential: server.credential
153
+ });
154
+ }
155
+ }
156
+ }
157
+ }
158
+ }
159
+
160
+ if (turnServers.length > 0) {
161
+ console.log(`[NativePeerConnection] Configured ${turnServers.length} TURN server(s)`);
162
+ }
163
+
164
+ return turnServers;
165
+ }
166
+
135
167
  /**
136
168
  * Create an offer
137
169
  * @param {Object} options