have client stop polling for public servers after game starts

This commit is contained in:
Evan
2025-02-12 12:08:50 -08:00
parent eae53b29cb
commit f448785476
2 changed files with 17 additions and 1 deletions
+10 -1
View File
@@ -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();
},
);
}
+7
View File
@@ -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``;