Skip to content

Commit

Permalink
lukebot-widget-common.js: Close WebSocket on before window unload
Browse files Browse the repository at this point in the history
This cleanly exits the Widget WebSocket thread and fixes "closed before
completing close handshake" Exception.
  • Loading branch information
lookeypl committed Feb 7, 2025
1 parent 7e3fd80 commit 30af11b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions LukeBot.Endpoint/Pages/js/lukebot-widget-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class LukeBotWidget
printDebug(`Connected to server at ${this.serverAddress}`);
}
this.socket.onclose = (e) => {
if (this.close)
this.close();

if (e.wasClean) {
printDebug(`Connection closed cleanly`);
} else {
Expand All @@ -56,6 +53,10 @@ class LukeBotWidget
this.messageError(error);
}
}

window.addEventListener("beforeunload", () => {
this.socket.close();
});
}

registerMessage(message, callback) {
Expand Down

0 comments on commit 30af11b

Please sign in to comment.