diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/transport.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/transport.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transport.js b/packages/meshbay-hub/src/meshbay_hub/static/transport.js index 1a28fb0..72c831f 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/transport.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/transport.js @@ -582,6 +582,23 @@ class MeshBayTransport { get newNodeBundleRecovery() { return this._newNodeBundleRecovery || null; } set newNodeBundleRecovery(v) { this._newNodeBundleRecovery = v; } + /** + * Tell a caller that connecting is getting somewhere. + * + * Only a caller that imposes its own deadline on `connect()` sets + * `onConnectProgress`, and only Search does: everywhere else a connection is + * opened one at a time and waits out the budgets in here. It exists so that + * deadline can measure *stalling* rather than elapsed time — a link slow + * enough to need twelve seconds is not the same thing as a node that is not + * answering, and a fixed number cannot tell them apart. + * + * Never lets a caller's callback break the connection it is reporting on. + */ + _noteConnectProgress(phase) { + if (!this.onConnectProgress) return; + try { this.onConnectProgress(phase); } catch { /* the caller's problem */ } + } + async connect(nodeId, jwtToken, groupId, gekRaw, sessionKeys, bundleKey, username, userId, joinCode, recoveryKey) { // Remembered for _reconnectLoop, which calls connect() again with these @@ -633,6 +650,7 @@ class MeshBayTransport { clearTimeout(timeout); this._connected = true; trace('channel_open', {}); + this._noteConnectProgress('channel_open'); resolve(); }; }); @@ -695,6 +713,14 @@ class MeshBayTransport { pc.oniceconnectionstatechange = () => { console.log('[MeshBay] ICE state:', pc.iceConnectionState); trace('ice_state', { state: pc.iceConnectionState }); + // `connected`/`completed` is the first moment this browser knows the peer + // is there at all: a candidate pair answered. `checking` is not — it is + // this side trying addresses that may all be dead. + if (pc === this._pc + && (pc.iceConnectionState === 'connected' + || pc.iceConnectionState === 'completed')) { + this._noteConnectProgress('ice_connected'); + } }; // Diagnostic-only: a periodic health ping and a resume-triggered one, so |