add keepalive ping, onclose event reason

This commit is contained in:
2025-07-02 06:41:43 -04:00
parent ed8d148d0a
commit 6088a2cbd3

View File

@ -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) => { ws.on("message", async (data) => {
try { try {
const message: WSEvent = JSON.parse(data.toString("utf-8")); const message: WSEvent = JSON.parse(data.toString("utf-8"));