From f4487854760fbd78249b8e53f769f0e086110c5c Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 12 Feb 2025 12:08:50 -0800 Subject: [PATCH] have client stop polling for public servers after game starts --- src/client/Main.ts | 11 ++++++++++- src/client/PublicLobby.ts | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/client/Main.ts b/src/client/Main.ts index 6e03edfa9..c952cc69a 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -15,6 +15,7 @@ import { consolex } from "../core/Consolex"; import "./components/FlagInput"; import { FlagInput } from "./components/FlagInput"; import page from "page"; +import { PublicLobby } from "./PublicLobby"; class Client { private gameStop: () => void; @@ -23,6 +24,8 @@ class Client { private flagInput: FlagInput | null = null; private joinModal: JoinPrivateLobbyModal; + private publicLobby: PublicLobby; + constructor() {} initialize(): void { @@ -37,6 +40,9 @@ class Client { if (!this.usernameInput) { consolex.warn("Username input element not found"); } + + this.publicLobby = document.querySelector("public-lobby") as PublicLobby; + window.addEventListener("beforeunload", (event) => { consolex.log("Browser is closing"); if (this.gameStop != null) { @@ -119,7 +125,10 @@ class Client { disableNPCs: event.detail.disableNPCs, creativeMode: event.detail.creativeMode, }, - () => this.joinModal.close(), + () => { + this.joinModal.close(); + this.publicLobby.stop(); + }, ); } diff --git a/src/client/PublicLobby.ts b/src/client/PublicLobby.ts index f1258e2d5..da4dfe658 100644 --- a/src/client/PublicLobby.ts +++ b/src/client/PublicLobby.ts @@ -54,6 +54,13 @@ export class PublicLobby extends LitElement { } } + public stop() { + if (this.lobbiesInterval !== null) { + clearInterval(this.lobbiesInterval); + this.lobbiesInterval = null; + } + } + render() { if (this.lobbies.length === 0) return html``;