Перейти к содержанию

WebSocket протокол

Подключение

WS /ws/v1?token=<jwt_or_guest_token>

Client → Server

subscribe

{ "type": "subscribe", "topic": "session:<uuid>" }
{ "type": "subscribe", "topic": "game:<uuid>" }

ping

{ "type": "ping" }

Server → Client

pong

{ "type": "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

  1. Exponential backoff: 1s, 2s, 4s … max 30s
  2. On connect: GET /games/{id}/state для синхронизации
  3. Re-subscribe to topics

Реализация

  • services/api/app/modules/realtime/ws.py
  • services/api/app/modules/realtime/manager.py
  • Redis Pub/Sub bridge из NATS events