add websocket error handling

This commit is contained in:
Evan
2025-02-12 13:31:22 -08:00
parent cc1291153c
commit 6d507914c9
2 changed files with 10 additions and 0 deletions
+5
View File
@@ -131,6 +131,11 @@ export class GameServer {
(c) => c.clientID != client.clientID,
);
});
client.ws.on("error", (error: Error) => {
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
client.ws.close(1002);
}
});
// In case a client joined the game late and missed the start message.
if (this._hasStarted) {
+5
View File
@@ -183,6 +183,11 @@ wss.on("connection", (ws, req) => {
console.log(`errror handling websocket message: ${error}`);
}
});
ws.on("error", (error: Error) => {
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
ws.close(1002);
}
});
});
function runGame() {