Connection Lifecycle#
This page explains how Waton connects, authenticates, and disconnects.
Connection states#
WAClient emits connection updates via client.on_connection_update.
Current status values emitted by the implementation include:
connectingpairing-successpairing-signedopenclose
The event object is ConnectionEvent with:
statusqr(optional)reason(optional)
Typical flow#
connect()is called.Status becomes
connecting.If credentials are not ready, QR values are emitted (still
connecting).After successful auth and stream success, status becomes
open.On disconnect/error, status becomes
closewith reason.
Minimal callback example#
async def on_connection_update(event):
print(f"status={event.status}")
if event.qr:
print("QR received")
if event.reason:
print(f"reason={event.reason}")
Reconnect behavior#
Reconnect-related behavior is controlled through configuration values in
DEFAULT_CONNECTION_CONFIG:
auto_restart_on_515max_restart_attempts
These are used to decide whether restart-required disconnects should trigger automatic reconnect attempts.
Keepalive and timeouts#
Important connection-related config keys:
connect_timeoutframe_timeoutkeepalive_intervalqr_timeout
If you tune these values, keep conservative defaults for production stability.
High-level App behavior#
App.run() wraps this lifecycle:
Calls
client.connect()Waits until connection status is
openRuns optional
@app.on_readycallbackKeeps loop alive until shutdown
If QR rendering package is installed, App prints terminal QR automatically.
Next steps#
Event stream details: Event Model
Message parsing and content types: Message Model
Sending and receiving patterns: Handling Messages