WebSocket протокол
Подключение
WS /ws/v1?token=<jwt_or_guest_token>
Client → Server
subscribe
{ "type": "subscribe", "topic": "session:<uuid>" }
{ "type": "subscribe", "topic": "game:<uuid>" }
ping
Server → Client
pong
subscribed
{ "type": "subscribed", "topic": "session:..." }
participant.joined
{
"type": "participant.joined",
"session_id": "...",
"participant_id": "...",
"display_name": "...",
"channel": "web|telegram"
}
game.state_changed
{
"type": "game.state_changed",
"game_id": "...",
"session_id": "...",
"state": {},
"view": {},
"status": "playing|finished"
}
Reconnect
- Exponential backoff: 1s, 2s, 4s … max 30s
- On connect:
GET /games/{id}/state для синхронизации
- Re-subscribe to topics
Реализация
services/api/app/modules/realtime/ws.py
services/api/app/modules/realtime/manager.py
- Redis Pub/Sub bridge из NATS events