Expand description
Protocol module for RuneCast WebSocket communication.
This module defines all message types exchanged between the frontend client and backend server over WebSocket connections.
§Architecture
┌─────────────────────────────────────────────────────────────────────┐
│ Protocol Layer │
├─────────────────────────────────────────────────────────────────────┤
│ envelope.rs - Message wrapper with seq/ack/timestamp │
│ types.rs - Shared data types (Grid, Position, etc.) │
│ client_messages - Client → Server message definitions │
│ server_messages - Server → Client message definitions │
└─────────────────────────────────────────────────────────────────────┘§Message Flow
Client Server
│ │
│──── Identify ──────────────────────▶│
│◀─── Ready (LobbySnapshot) ──────────│
│ │
│──── JoinChannelLobby ──────────────▶│
│◀─── LobbyJoined ────────────────────│
│ │
│──── StartGame ─────────────────────▶│
│◀─── GameStarted ────────────────────│
│ │
│──── SubmitWord ────────────────────▶│
│◀─── WordScored ─────────────────────│
│◀─── TurnChanged ────────────────────│§Envelope Format (Optional)
Messages can be sent raw (legacy) or wrapped in an envelope (new protocol):
// Legacy (still supported)
{"type": "heartbeat"}
// With envelope
{"seq": 42, "ack": 41, "ts": 1701234567890, "payload": {"type": "heartbeat"}}§Migration Strategy
This module is designed to coexist with the legacy websocket/messages.rs.
During migration:
- New code imports from
protocol:: - Compatibility functions convert between old and new formats
- Once migration is complete, remove legacy module
Re-exports§
pub use client_messages::ClientMessage;pub use envelope::Envelope;pub use envelope::MaybeEnveloped;pub use server_messages::LobbySnapshot;pub use server_messages::ServerMessage;pub use types::*;
Modules§
- client_
messages - Client-to-server messages.
- compat
- Module for converting between legacy and new message formats.
- envelope
- Message envelope for reliable delivery and synchronization.
- server_
messages - Server-to-client messages.
- types
- Shared types used in protocol messages.
Constants§
- HEARTBEAT_
INTERVAL_ MS - Recommended heartbeat interval (client should send heartbeat this often).
- HEARTBEAT_
TIMEOUT_ MS - Heartbeat timeout (server closes connection if no heartbeat received).
- MAX_
MESSAGE_ SIZE - Maximum message size in bytes.
- PROTOCOL_
VERSION - Protocol version for compatibility checks.
- RECONNECT_
GRACE_ MS - Grace period for reconnection before session expires.