From c179249cdd7439fe132a8f5f7a518b9d0e4698af Mon Sep 17 00:00:00 2001 From: Ryan <7389646+ryanbarlow97@users.noreply.github.com> Date: Sun, 18 Jan 2026 11:07:52 +0000 Subject: [PATCH] [BugFix] Join Lobby Bugfix (#2947) ## Description: If a WebSocket was "connecting", but the user un-clicks the lobby in that time, it doesn't remove them from the lobby, and they would still be put into the game. @evanpelle needed for v29 imo. It also fixes an issue where it wouldn't update your URL back to the home url when unclicking the lobby (websocket issue or not). This is a hotfix to fix that. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: w.o.n --- src/client/Main.ts | 6 ++++++ src/client/Transport.ts | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/client/Main.ts b/src/client/Main.ts index 88fe223f4..98414eca7 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -868,6 +868,12 @@ class Client { this.gameStop(); this.gameStop = null; + try { + history.replaceState(null, "", "/"); + } catch (e) { + console.warn("Failed to restore URL on leave:", e); + } + document.body.classList.remove("in-game"); crazyGamesSDK.gameplayStop(); diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 1f35131a4..d370c6ba8 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -725,10 +725,18 @@ export class Transport { this.socket.onclose = null; this.socket.onerror = null; - // Close the connection if it's still open - if (this.socket.readyState === WebSocket.OPEN) { - this.socket.close(); + // Close the connection if it's still open or still connecting + try { + if ( + this.socket.readyState === WebSocket.OPEN || + this.socket.readyState === WebSocket.CONNECTING + ) { + this.socket.close(); + } + } catch (e) { + console.warn("Error while closing WebSocket:", e); } + this.socket = null; } }