node-rtc-connection 1.0.9 → 1.0.10

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
@@ -1495,12 +1495,19 @@ function requireICEGatherer () {
1495
1495
 
1496
1496
  for (const [name, addrs] of Object.entries(interfaces)) {
1497
1497
  for (const addr of addrs) {
1498
- // Skip internal and IPv6 for now
1499
- if (addr.internal || addr.family !== 'IPv4') {
1498
+ // Skip internal/loopback addresses
1499
+ if (addr.internal) {
1500
1500
  continue;
1501
1501
  }
1502
1502
 
1503
- const priority = this._calculatePriority('host', 65535, foundation);
1503
+ // Support both IPv4 and IPv6
1504
+ if (addr.family !== 'IPv4' && addr.family !== 'IPv6') {
1505
+ continue;
1506
+ }
1507
+
1508
+ // Calculate priority (IPv4 slightly higher than IPv6)
1509
+ const typePreference = addr.family === 'IPv4' ? 65535 : 65534;
1510
+ const priority = this._calculatePriority('host', typePreference, foundation);
1504
1511
 
1505
1512
  candidates.push({
1506
1513
  candidate: `candidate:${foundation} 1 udp ${priority} ${addr.address} ${port} typ host`,
@@ -1598,7 +1605,7 @@ function requireICEGatherer () {
1598
1605
  _getLocalIPForRemote() {
1599
1606
  const interfaces = os.networkInterfaces();
1600
1607
 
1601
- // Prefer non-internal IPv4 addresses
1608
+ // Prefer non-internal IPv4 addresses first
1602
1609
  for (const [name, addrs] of Object.entries(interfaces)) {
1603
1610
  for (const addr of addrs) {
1604
1611
  if (!addr.internal && addr.family === 'IPv4') {
@@ -1607,6 +1614,15 @@ function requireICEGatherer () {
1607
1614
  }
1608
1615
  }
1609
1616
 
1617
+ // Fall back to IPv6 if no IPv4 available
1618
+ for (const [name, addrs] of Object.entries(interfaces)) {
1619
+ for (const addr of addrs) {
1620
+ if (!addr.internal && addr.family === 'IPv6') {
1621
+ return addr.address;
1622
+ }
1623
+ }
1624
+ }
1625
+
1610
1626
  return '0.0.0.0';
1611
1627
  }
1612
1628
 
@@ -2827,15 +2843,15 @@ function requireNativePeerConnectionFactory () {
2827
2843
  const usingRelay = this._selectedLocalCandidate?.type === 'relay' ||
2828
2844
  this._selectedRemoteCandidate?.type === 'relay';
2829
2845
 
2830
- // if (!usingRelay) {
2831
- // // Tie-breaking: only connect if our port is higher than remote port
2832
- // // This ensures only one peer connects, avoiding the race condition
2833
- // // Note: This only works for direct connections (host/srflx)
2834
- // if (this._localPort < this._remotePort) {
2835
- // console.log(`[NativePeerConnection] Not connecting (local port ${this._localPort} < remote port ${this._remotePort}), waiting for incoming`);
2836
- // return;
2837
- // }
2838
- // }
2846
+ if (!usingRelay) {
2847
+ // Tie-breaking: only connect if our port is higher than remote port
2848
+ // This ensures only one peer connects, avoiding the race condition
2849
+ // Note: This only works for direct connections (host/srflx)
2850
+ if (this._localPort < this._remotePort) {
2851
+ console.log(`[NativePeerConnection] Not connecting (local port ${this._localPort} < remote port ${this._remotePort}), waiting for incoming`);
2852
+ return;
2853
+ }
2854
+ }
2839
2855
 
2840
2856
  console.log(`[NativePeerConnection] Connecting to ${this._remoteAddress}:${this._remotePort}`);
2841
2857
  if (usingRelay) {
@@ -3100,7 +3116,7 @@ a=max-message-size:262144
3100
3116
  _getLocalIPAddress() {
3101
3117
  const interfaces = os.networkInterfaces();
3102
3118
 
3103
- // Try to find a non-internal IPv4 address
3119
+ // Try to find a non-internal IPv4 address first
3104
3120
  for (const name of Object.keys(interfaces)) {
3105
3121
  for (const iface of interfaces[name]) {
3106
3122
  if (iface.family === 'IPv4' && !iface.internal) {
@@ -3109,6 +3125,15 @@ a=max-message-size:262144
3109
3125
  }
3110
3126
  }
3111
3127
 
3128
+ // Fall back to IPv6 if no IPv4 available
3129
+ for (const name of Object.keys(interfaces)) {
3130
+ for (const iface of interfaces[name]) {
3131
+ if (iface.family === 'IPv6' && !iface.internal) {
3132
+ return iface.address;
3133
+ }
3134
+ }
3135
+ }
3136
+
3112
3137
  // Fallback to localhost
3113
3138
  return '127.0.0.1';
3114
3139
  }