WaClient does not reconnect automatically. This is a deliberate design choice: reconnection policy (backoff, max retries, alerting) belongs to your application. You listen for connection: close and decide what to do.
Internal recovery layers
The โno auto-reconnectโ rule applies to the session lifecycle: once a connection: close event fires, the client will not reopen by itself. Two lower-level retries do live inside the stack though โ you will see them in logs and you do not need to handle them.
- WebSocket transport. If the socket drops before a successful noise handshake,
WaComms retries internally every reconnectIntervalMs (default 2000) up to maxReconnectAttempts. Once the handshake completes, the counter resets and any subsequent drop surfaces as a connection event for your app to handle.
- Pairing transition. Right after a QR/code pair succeeds, the client restarts the socket as a registered session. No
connection: close event fires for this โ it is invisible from the outside.
The client_too_old (HTTP 405) recovery covered below is a third, opt-in layer.
Connection lifecycle
The connection event
connection is a discriminated union on status:
On close:
isLogout: true โ the device was unlinked (server-side logout). Do not reconnect; the credentials are gone and you must re-pair.
isLogout: false โ a transient drop. Safe to reconnect with the stored credentials.
A reconnection loop with backoff
Recovering from client_too_old (HTTP 405)
If the server starts rejecting the noise handshake with failure_client_too_old, the bundled WA Web version is out of date. Two options:
Both are stopgaps โ upgrade zapo when a release ships with a refreshed default.
After reconnecting
Some state is connection-scoped and must be re-established after a successful reconnect:
- Presence subscriptions โ re-
subscribe() to any contacts you were watching (Presence).
- Newsletter live updates โ re-
subscribeLiveUpdates() if you rely on them.
Persisted state (credentials, Signal sessions, app-state) is restored from the store automatically โ you do not re-pair on a normal reconnect.
Graceful shutdown
Call disconnect() for a clean shutdown that keeps credentials so you can resume later:
This flushes pending write-behind data and closes the socket without unlinking the device.