From fa31e7f8db61efe085f7d8a317e6a8640ebb3f46 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Thu, 12 Aug 2021 20:18:05 +0200 Subject: :sparkles: gateway --- gateway/src/util/setHeartbeat.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 gateway/src/util/setHeartbeat.ts (limited to 'gateway/src/util/setHeartbeat.ts') diff --git a/gateway/src/util/setHeartbeat.ts b/gateway/src/util/setHeartbeat.ts new file mode 100644 index 00000000..9f88b481 --- /dev/null +++ b/gateway/src/util/setHeartbeat.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