Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions packages/client/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,21 @@ export class MitzoConnection {
}
}

/** Force a reconnect check — call from native lifecycle hooks (e.g. Capacitor appStateChange). */
/**
* Force a reconnect — call from native lifecycle hooks (e.g. Capacitor
* appStateChange) and browser visibility events.
*
* iOS kills WebSocket connections during background without updating
* readyState, so we NEVER trust the old socket after a foreground
* transition. Always tear down and create a fresh connection. Any
* sends that arrive during the reconnect window queue in pendingSends
* and flush after the welcome handshake completes.
*/
checkAndReconnect(): void {
if (!this.ws || this.ws.readyState !== WS_READY_STATE.OPEN) {
if (this.reconnectTimer) return;
this.defuseOldWs();
this._connected = false;
this.listener?.({ type: '_close' });
this.doConnect();
}
if (this.reconnectTimer) return;
this.defuseOldWs();
this._connected = false;
this.listener?.({ type: '_close' });
this.doConnect();
}
}
Loading