-
Mahmoud Aglan authored
New core module handles ALL connection edge cases: TAB REFRESH RECOVERY: - Active match stored in localStorage with timestamp - On app boot, checks for recoverable match (< 5 min old) - Automatically re-enters the game scene with recovered state - Fetches latest state from server immediately TAB VISIBILITY (switch/minimize): - Pauses polling when tab is hidden (saves bandwidth) - Resumes and immediately fetches latest state on return - Resets disconnect timers on tab return OPPONENT DISCONNECT DETECTION: - Tracks lastOpponentActivity timestamp - After 30s: fires onOpponentDisconnect (show warning UI) - After 60s: fires onOpponentAbandon (auto-claim win) - If opponent comes back: fires onOpponentReconnect NETWORK LOSS HANDLING: - If server unreachable for 10s: fires onConnectionLost - On recovery: fires onConnectionRestored - Polling continues with error tolerance SERVER PING (keep-alive): - Every 10s, pings server with player ID + timestamp - Stored in game_state.ping field - Opponent's polling reads this to know sender is alive API: - create(matchId, gameType, callbacks) — start session - destroy() — clean up timers + localStorage - getRecoverableMatch() — check for resume on boot - markOpponentActive() — call when opponent data received - isConnected() / isOpponentConnected() — status checks Engine updated: - Imports match-session on boot - Checks for recoverable match after auth - Auto-resumes game if found Co-Authored-By:Claude Opus 4.6 <noreply@anthropic.com>
412ee8f6