Connection Lifecycle

The SDK manages connection state and reconnects automatically on network interruption.

connect()

Opens the WebSocket connection. Automatically:

  • 1. Generates or retrieves X25519 identity keypair from secure storage
  • 2. Publishes your public key to the key directory (PUT keyDirectoryEndpoint/me)
  • 3. Calls getUserJwt() to get a fresh user JWT
  • 4. Sends JWT to your tokenExchangeEndpoint to obtain a DropOnAir access token
  • 5. Connects to the DropOnAir WebSocket relay
  • 6. Fetches and decrypts offline messages (messages received while disconnected)
const client = await initialize({ ..., autoConnect: false });

// Connect when the user logs in
await client.connect();

// Disconnect when the user logs out
client.disconnect();

Auto-reconnect behaviour

The SDK fires a RECONNECTING event before each retry and a CONNECTED event when re-established. Offline messages are fetched again on each successful reconnect.