diff --git a/src/client/RankedQueue.ts b/src/client/RankedQueue.ts index b4767ce16..da448d1be 100644 --- a/src/client/RankedQueue.ts +++ b/src/client/RankedQueue.ts @@ -57,16 +57,6 @@ export class RankedQueue extends LitElement { return this; } - /** - * Check if the current mode is a ranked mode (has ELO tracking) - */ - private get isRankedMode(): boolean { - return ( - this.queueType === "ranked" && - (this.gameMode === "ffa" || this.gameMode === "duel") - ); - } - disconnectedCallback() { super.disconnectedCallback(); this.cleanup(); @@ -205,8 +195,12 @@ export class RankedQueue extends LitElement { this.isConnecting = false; }; - this.ws.onclose = () => { - console.log("WebSocket closed"); + this.ws.onclose = (event) => { + console.log("WebSocket closed", { + code: event.code, + reason: event.reason, + wasClean: event.wasClean, + }); this.ws = null; // Attempt reconnection if we were in queue @@ -278,6 +272,13 @@ export class RankedQueue extends LitElement { this.inQueue = false; break; + case "ping": + // Respond to server ping to keep connection alive + if (this.ws && this.ws.readyState === WebSocket.OPEN) { + this.ws.send(JSON.stringify({ type: "pong", timestamp: Date.now() })); + } + break; + default: console.log("Unknown message type:", message.type); } @@ -356,31 +357,6 @@ export class RankedQueue extends LitElement { this.cleanup(); } - private setQueueType(type: QueueType) { - if (this.inQueue || this.isConnecting) { - return; - } - if (this.queueType !== type) { - this.queueType = type; - this.gameMode = "ffa"; - if (type === "ranked") { - this.fetchLeaderboard(); - } - } - } - - private setGameMode(mode: GameMode) { - if (this.inQueue || this.isConnecting) { - return; - } - if (this.gameMode !== mode) { - this.gameMode = mode; - if (this.queueType === "ranked") { - this.fetchLeaderboard(); - } - } - } - public async open() { this.modalEl?.open(); await Promise.all([this.fetchPlayerElo(), this.fetchLeaderboard()]); @@ -393,140 +369,59 @@ export class RankedQueue extends LitElement { this.modalEl?.close(); } + private setGameMode(mode: GameMode) { + if (this.inQueue) { + return; // Don't allow mode change while in queue + } + this.gameMode = mode; + this.fetchLeaderboard(); // Refresh leaderboard for new mode + } + render() { return html`
- +
- - ${this.queueType === "ranked" - ? html` -
- - -
- ` - : html` -
- - - - -
- `} - - ` - : ""} + + - ${this.isRankedMode && this.showLeaderboard + ${this.showLeaderboard ? html`