From 5e86d7ab9c5200d794c3adb2b422d20a2aefd2ce Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 13 Aug 2022 02:00:50 +0200 Subject: restructure to single project --- src/gateway/util/Heartbeat.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/gateway/util/Heartbeat.ts (limited to 'src/gateway/util/Heartbeat.ts') diff --git a/src/gateway/util/Heartbeat.ts b/src/gateway/util/Heartbeat.ts new file mode 100644 index 00000000..f6871cfe --- /dev/null +++ b/src/gateway/util/Heartbeat.ts @@ -0,0 +1,11 @@ +import { CLOSECODES } from "./Constants"; +import { WebSocket } from "./WebSocket"; + +// TODO: make heartbeat timeout configurable +export function setHeartbeat(socket: WebSocket) { + if (socket.heartbeatTimeout) clearTimeout(socket.heartbeatTimeout); + + socket.heartbeatTimeout = setTimeout(() => { + return socket.close(CLOSECODES.Session_timed_out); + }, 1000 * 45); +} -- cgit 1.5.1