node-rtc-connection 1.0.14 → 1.0.15

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.14",
3
+ "version": "1.0.15",
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",
@@ -336,16 +336,43 @@ class RTCIceTransport extends EventEmitter {
336
336
  throw new TypeError('Candidate must be an object');
337
337
  }
338
338
 
339
- // Add to remote candidates list
339
+ // Ensure candidate is properly formatted
340
+ // If it's a plain object with a candidate string, parse it
341
+ let parsedCandidate = candidate;
342
+ const RTCIceCandidate = require('./RTCIceCandidate');
343
+
344
+ if (!(candidate instanceof RTCIceCandidate)) {
345
+ // Try to create an RTCIceCandidate to parse and validate
346
+ try {
347
+ parsedCandidate = new RTCIceCandidate(candidate);
348
+ } catch (err) {
349
+ console.warn('Failed to parse remote candidate:', err.message);
350
+ // Store the original anyway for compatibility
351
+ this._remoteCandidates.push(candidate);
352
+ return;
353
+ }
354
+ } else {
355
+ parsedCandidate = candidate;
356
+ }
357
+
358
+ // Validate that candidate has required properties for connectivity checks
359
+ if (!parsedCandidate.address || parsedCandidate.port === null || parsedCandidate.port === undefined) {
360
+ console.warn('Remote candidate missing address or port, skipping connectivity checks');
361
+ // Store the original candidate for compatibility
362
+ this._remoteCandidates.push(candidate);
363
+ return;
364
+ }
365
+
366
+ // Store the original candidate (for getRemoteCandidates compatibility)
340
367
  this._remoteCandidates.push(candidate);
341
368
 
342
369
  // Start connectivity checks if we're in checking state
343
370
  if (this._state === RTCIceTransportState.CHECKING && this._localCandidates.length > 0) {
344
- // Create pairs for this new remote candidate with all local candidates
371
+ // Create pairs using the parsed candidate for connectivity checks
345
372
  for (const localCandidate of this._localCandidates) {
346
373
  const pair = {
347
374
  local: localCandidate,
348
- remote: candidate,
375
+ remote: parsedCandidate,
349
376
  state: 'waiting'
350
377
  };
351
378
  this._candidatePairs.push(pair);
@@ -726,12 +753,27 @@ class RTCIceTransport extends EventEmitter {
726
753
  * @param {Object} pair - Candidate pair
727
754
  * @private
728
755
  */
756
+ /**
757
+ * Send ICE connectivity check to remote candidate
758
+ * @param {Object} pair - Candidate pair
759
+ * @private
760
+ */
729
761
  _sendConnectivityCheck(pair) {
730
762
  const socket = this._sockets.get(pair.local.foundation);
731
763
  if (!socket || socket.type === 'turn') {
732
764
  return; // Skip TURN candidates for now
733
765
  }
734
766
 
767
+ // Validate remote candidate has required properties
768
+ if (!pair.remote.address || !pair.remote.port) {
769
+ console.warn('Cannot send connectivity check: remote candidate missing address or port', {
770
+ address: pair.remote.address,
771
+ port: pair.remote.port,
772
+ candidate: pair.remote.candidate
773
+ });
774
+ return;
775
+ }
776
+
735
777
  const transactionId = crypto.randomBytes(12);
736
778
  const request = this._createBindingRequest(transactionId);
737
779
 
@@ -742,7 +784,7 @@ class RTCIceTransport extends EventEmitter {
742
784
  }
743
785
  });
744
786
  } catch (err) {
745
- console.error(`Error sending connectivity check:`, err);
787
+ console.error(`Error sending connectivity check to ${pair.remote.address || 'unknown'}:${pair.remote.port || 'unknown'}:`, err);
746
788
  }
747
789
  }
748
790