From 6088a2cbd3cbf14d6fb44a74b01cf89e39b68d41 Mon Sep 17 00:00:00 2001 From: matty Date: Wed, 2 Jul 2025 06:41:43 -0400 Subject: [PATCH] add keepalive ping, onclose event reason --- src/main.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.ts b/src/main.ts index 56cab7a..f1ead82 100644 --- a/src/main.ts +++ b/src/main.ts @@ -159,6 +159,16 @@ ws.on("upgrade", () => { ); }); +ws.on("close", (event: CloseEvent) => { + console.log(`Connection closed: ${event.reason}`); +}); + +ws.on("open", () => { + setInterval(() => { + ws.send(JSON.stringify({ type: "ping" })); + }, 20000); +}); + ws.on("message", async (data) => { try { const message: WSEvent = JSON.parse(data.toString("utf-8"));