WebSocket Protocol
Magne uses a WebSocket connection for real-time event delivery. All presence updates, messages, typing indicators, and voice states are pushed through this channel.Connection
Connection Lifecycle
- Connect — Client opens WSS connection with token
- Authenticated — Server validates token, registers the session
- Events flow — Server pushes events as JSON frames
- Heartbeat — Server tracks connection health
- Disconnect — Client closes connection or token expires
Message Format
All WebSocket messages are JSON-encoded with a consistent structure:Multi-Session
Users can have multiple simultaneous WebSocket connections (e.g., desktop + mobile). The server tracks connection count per user and only triggers cleanup (voice disconnect, presence offline) when all connections close.This prevents false presence flickers during reconnection or when switching
devices.
Reconnection
If disconnected, clients should implement exponential backoff:- Wait 1 second, reconnect
- If failed, wait 2 seconds
- If failed, wait 4 seconds
- Cap at 30 seconds between attempts
- Refresh access token if expired before reconnecting