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