feat: realtime multiplayer system for Chess and Ludo
New core module: realtime.js
- WebSocket connection to Supabase Realtime
- Auto-reconnect on disconnect (3s retry)
- Heartbeat every 30s
- Subscribe to any table row by filter
- subscribeMatch(), subscribeLudoMatch(), subscribeQueue() helpers
- Unsubscribe cleanup on leave
Chess live (logic/live.js) rewritten:
- startMatchmaking() — joins queue + subscribes for match found
- joinMatch() — subscribes to match row, fires onMove/onStateChange
- sendMove() — updates match with fen, move, move_count
- sendResign(), sendDrawOffer(), sendEmote()
- Properly increments move_count for realtime detection
Ludo live (logic/live.js) new:
- joinMatch() — subscribes to ludo_matches row
- sendRoll() — updates positions, current_turn, dice_value
- sendEnd() — marks game complete
API game.php updated:
- handleGameMove now supports: move_count, game_state, time remaining
- All fields optional (only updates what's sent)
- updated_at timestamp on every move (triggers realtime broadcast)
Architecture: Player A updates row → Supabase broadcasts → Player B receives
Co-Authored-By:
Claude Opus 4.6 <noreply@anthropic.com>
Showing
public/js/core/realtime.js
0 → 100644
32.4 KB
screenshots/dice-start.png
0 → 100644
32.9 KB
32.9 KB
32.9 KB