Fix End Game showing false 'Connection lost' error

Add _intentionalClose flag to suppress error when server closes
WebSocket after game_ended broadcast. Clean transition to lobby.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
adlee-was-taken 2026-02-21 20:39:43 -05:00
parent bae5d8da3c
commit 62e7d4e1dd

View File

@ -639,7 +639,10 @@ class GolfGame {
this.ws.onclose = () => { this.ws.onclose = () => {
console.log('Disconnected from server'); console.log('Disconnected from server');
if (!this._intentionalClose) {
this.showError('Connection lost. Please refresh the page.'); this.showError('Connection lost. Please refresh the page.');
}
this._intentionalClose = false;
}; };
this.ws.onerror = (error) => { this.ws.onerror = (error) => {
@ -881,8 +884,9 @@ class GolfGame {
case 'game_ended': case 'game_ended':
// Host ended the game or player was kicked // Host ended the game or player was kicked
this.ws.close(); this._intentionalClose = true;
this.showLobby(); if (this.ws) this.ws.close();
this.showScreen('lobby');
if (data.reason) { if (data.reason) {
this.showError(data.reason); this.showError(data.reason);
} }