node-rtc-connection 1.0.14 → 1.0.16

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.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import require$$0$1 from 'events';
2
2
  import require$$0 from 'dgram';
3
3
  import require$$3 from 'crypto';
4
- import require$$4 from 'os';
4
+ import require$$5 from 'os';
5
5
  import require$$1 from 'net';
6
6
 
7
7
  function getDefaultExportFromCjs (x) {
@@ -1770,16 +1770,43 @@ function requireRTCIceTransport () {
1770
1770
  throw new TypeError('Candidate must be an object');
1771
1771
  }
1772
1772
 
1773
- // Add to remote candidates list
1773
+ // Ensure candidate is properly formatted
1774
+ // If it's a plain object with a candidate string, parse it
1775
+ let parsedCandidate = candidate;
1776
+ const RTCIceCandidate = requireRTCIceCandidate();
1777
+
1778
+ if (!(candidate instanceof RTCIceCandidate)) {
1779
+ // Try to create an RTCIceCandidate to parse and validate
1780
+ try {
1781
+ parsedCandidate = new RTCIceCandidate(candidate);
1782
+ } catch (err) {
1783
+ console.warn('Failed to parse remote candidate:', err.message);
1784
+ // Store the original anyway for compatibility
1785
+ this._remoteCandidates.push(candidate);
1786
+ return;
1787
+ }
1788
+ } else {
1789
+ parsedCandidate = candidate;
1790
+ }
1791
+
1792
+ // Validate that candidate has required properties for connectivity checks
1793
+ if (!parsedCandidate.address || parsedCandidate.port === null || parsedCandidate.port === undefined) {
1794
+ console.warn('Remote candidate missing address or port, skipping connectivity checks');
1795
+ // Store the original candidate for compatibility
1796
+ this._remoteCandidates.push(candidate);
1797
+ return;
1798
+ }
1799
+
1800
+ // Store the original candidate (for getRemoteCandidates compatibility)
1774
1801
  this._remoteCandidates.push(candidate);
1775
1802
 
1776
1803
  // Start connectivity checks if we're in checking state
1777
1804
  if (this._state === RTCIceTransportState.CHECKING && this._localCandidates.length > 0) {
1778
- // Create pairs for this new remote candidate with all local candidates
1805
+ // Create pairs using the parsed candidate for connectivity checks
1779
1806
  for (const localCandidate of this._localCandidates) {
1780
1807
  const pair = {
1781
1808
  local: localCandidate,
1782
- remote: candidate,
1809
+ remote: parsedCandidate,
1783
1810
  state: 'waiting'
1784
1811
  };
1785
1812
  this._candidatePairs.push(pair);
@@ -1895,7 +1922,7 @@ function requireRTCIceTransport () {
1895
1922
  * @private
1896
1923
  */
1897
1924
  async _gatherHostCandidates() {
1898
- const os = require$$4;
1925
+ const os = require$$5;
1899
1926
  const interfaces = os.networkInterfaces();
1900
1927
 
1901
1928
  for (const [name, addrs] of Object.entries(interfaces)) {
@@ -2160,12 +2187,27 @@ function requireRTCIceTransport () {
2160
2187
  * @param {Object} pair - Candidate pair
2161
2188
  * @private
2162
2189
  */
2190
+ /**
2191
+ * Send ICE connectivity check to remote candidate
2192
+ * @param {Object} pair - Candidate pair
2193
+ * @private
2194
+ */
2163
2195
  _sendConnectivityCheck(pair) {
2164
2196
  const socket = this._sockets.get(pair.local.foundation);
2165
2197
  if (!socket || socket.type === 'turn') {
2166
2198
  return; // Skip TURN candidates for now
2167
2199
  }
2168
2200
 
2201
+ // Validate remote candidate has required properties
2202
+ if (!pair.remote.address || !pair.remote.port) {
2203
+ console.warn('Cannot send connectivity check: remote candidate missing address or port', {
2204
+ address: pair.remote.address,
2205
+ port: pair.remote.port,
2206
+ candidate: pair.remote.candidate
2207
+ });
2208
+ return;
2209
+ }
2210
+
2169
2211
  const transactionId = crypto.randomBytes(12);
2170
2212
  const request = this._createBindingRequest(transactionId);
2171
2213
 
@@ -2176,7 +2218,7 @@ function requireRTCIceTransport () {
2176
2218
  }
2177
2219
  });
2178
2220
  } catch (err) {
2179
- console.error(`Error sending connectivity check:`, err);
2221
+ console.error(`Error sending connectivity check to ${pair.remote.address || 'unknown'}:${pair.remote.port || 'unknown'}:`, err);
2180
2222
  }
2181
2223
  }
2182
2224
 
@@ -4785,7 +4827,7 @@ function requireRTCPeerConnection () {
4785
4827
  const { address, port } = await this._networkTransport.listen(0, '0.0.0.0');
4786
4828
 
4787
4829
  // Get local address (try to find non-localhost)
4788
- const os = require$$4;
4830
+ const os = require$$5;
4789
4831
  const interfaces = os.networkInterfaces();
4790
4832
  let localAddress = '127.0.0.1';
4791
4833
 
@@ -5042,10 +5084,11 @@ function requireRTCPeerConnection () {
5042
5084
  if (this._sctpTransport.state === 'connected') {
5043
5085
  for (const channel of this._dataChannels.values()) {
5044
5086
  if (channel.readyState === 'connecting') {
5045
- channel._setStateToOpen();
5046
-
5047
- // Hook up channel to network transport
5087
+ // Hook up channel to network transport first
5048
5088
  this._connectChannelToNetwork(channel);
5089
+
5090
+ // Then set state to open (emits 'open' event)
5091
+ channel._setStateToOpen();
5049
5092
  }
5050
5093
  }
5051
5094
  }
@@ -5274,7 +5317,7 @@ function requireRTCPeerConnection () {
5274
5317
  return RTCPeerConnection_1;
5275
5318
  }
5276
5319
 
5277
- var version = "1.0.14";
5320
+ var version = "1.0.16";
5278
5321
  var require$$10 = {
5279
5322
  version: version};
5280
5323