@yz-social/webrtc 0.1.13 → 0.1.14

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.
Files changed (2) hide show
  1. package/index.js +8 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -46,9 +46,8 @@ export class WebRTC {
46
46
  if (!pc) return null;
47
47
  const state = pc.connectionState;
48
48
  if (state === 'connected') return this.signalsReadyResolver?.();
49
- if (['new', 'connecting'].includes(state)) return null;
50
- // closed, disconnected, failed: resolve this.closed promise.
51
- this.log('connectionstatechange signaling/connection:', pc.signalingState, state);
49
+ if (['new', 'connecting'/*, 'failed'*/].includes(state)) return null; // On failed, iceconnectionstatechange will restartIce.
50
+ // closed, disconnected: resolve this.closed promise.
52
51
  this.cleanup();
53
52
  return resolve(pc);
54
53
  };
@@ -75,7 +74,7 @@ export class WebRTC {
75
74
  case 'completed':
76
75
  this._resolveIceCompleted?.(true);
77
76
  break;
78
- case 'failed':
77
+ case 'failed': // This doesn't mean the connection is broken. It could just be looking for a better transport.
79
78
  this.pc.restartIce();
80
79
  break;
81
80
  default:
@@ -206,7 +205,8 @@ export class WebRTC {
206
205
  // This is used by a peer that is receiving signals in an out-of-band network request, and waiting for a response. (Compare transferSignals.)
207
206
  return this.responseSerializer = this.responseSerializer.then(async () => {
208
207
  this.log('respond', signals.length, 'signals');
209
- const {promise, resolve} = Promise.withResolvers();
208
+ const {promise, resolve} = Promise.withResolvers(); // FIXME: this breaks Firefox.
209
+ //const {promise, resolve} = {}; // FIXME: tests "pass" on Firefox with this version.
210
210
  this.signalsReadyResolver = resolve;
211
211
  await this.onSignals(signals);
212
212
  if (!this.pendingSignals.length) await promise;
@@ -330,11 +330,12 @@ export class WebRTC {
330
330
  return;
331
331
  }
332
332
  const remote = stats.get(candidatePair.remoteCandidateId);
333
- const {protocol, candidateType, address} = remote;
333
+ const {protocol, candidateType, address, port} = remote;
334
334
  const now = Date.now();
335
335
  const statsElapsed = now - this.connectionStartTime;
336
+ const local = stats.get(candidatePair.localCandidateId);
336
337
  Object.assign(this, {stats, transport, candidatePair, remote, protocol, candidateType, statsTime: now, statsElapsed});
337
- if (doLogging) console.info(this.name, 'connected', protocol, candidateType, address, (statsElapsed/1e3).toFixed(1));
338
+ if (doLogging) console.info(new Date(), this.name, this.pc?.connectionState, protocol, candidateType, `${local.address}:${local.port}=>${address}:${port}`, (statsElapsed/1e3).toFixed(1));
338
339
  }
339
340
 
340
341
  static getPublicIP(stunServer = "stun:stun.l.google.com:19302") { // Promise external/WAN/public IP addresses for this device.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yz-social/webrtc",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Streamlined portable webrtc management of p2p and client2server.",
5
5
  "keywords": [
6
6
  "webrtc",