Connecting
Connect to the WebSocket server with authentication:Subscriptions
Subscribe to different channels to receive updates:Player Updates
Receive updates when a player’s state changes:Leaderboard Updates
Get real-time leaderboard changes:Lobby Updates
For multiplayer features:Chat Messages
Real-time chat:Event Types
Player Events
| Event | Description |
|---|---|
xp_updated | Player’s XP changed |
level_up | Player reached a new level |
currency_updated | Currency balance changed |
lives_updated | Lives count changed |
badge_earned | New badge awarded |
quest_progress | Quest progress updated |
quest_completed | Quest finished |
quest_unlocked | New quest available |
Leaderboard Events
| Event | Description |
|---|---|
leaderboard_updated | Rankings changed |
rank_changed | Player’s rank changed |
new_high_score | New top score recorded |
Lobby Events
| Event | Description |
|---|---|
player_joined | Player entered lobby |
player_left | Player exited lobby |
player_ready | Player ready status changed |
lobby_started | Game/session started |
lobby_closed | Lobby disbanded |
Chat Events
| Event | Description |
|---|---|
chat_message | New message received |
player_typing | Player is typing |
message_deleted | Message was removed |
Sending Events
Emit events to the server:Connection Management
Reconnection
The SDK handles reconnection automatically, but you can customize behavior:Token Refresh
WebSocket tokens expire after 15 minutes. Implement refresh logic:Rate Limiting
WebSocket events are rate-limited to prevent abuse:| Limit | Value |
|---|---|
| Events per second | 10 |
| Subscriptions per connection | 50 |
| Message size | 64KB |
Best Practices
Unsubscribe when done
Remove subscriptions when leaving screens to reduce bandwidth.
Handle disconnections
Implement reconnection logic and re-subscribe after reconnecting.
Batch updates
Update UI in batches if receiving many events quickly.
Use heartbeats
Monitor connection health with ping/pong events.