summary refs log tree commit diff
path: root/gateway/src/util/Heartbeat.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-02 15:12:47 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-02 15:12:47 +0200
commit7bd0a2004c9d7f1c59b510a5462b82c4b0a0ce7a (patch)
tree4e77c193c08b2acb234981a6244836e1c5398bcf /gateway/src/util/Heartbeat.ts
parentMerge pull request #410 from TheArcaneBrony/master (diff)
downloadserver-7bd0a2004c9d7f1c59b510a5462b82c4b0a0ce7a.tar.xz
:art: restructure gateway
Diffstat (limited to 'gateway/src/util/Heartbeat.ts')
-rw-r--r--gateway/src/util/Heartbeat.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/gateway/src/util/Heartbeat.ts b/gateway/src/util/Heartbeat.ts
new file mode 100644
index 00000000..f6871cfe
--- /dev/null
+++ b/gateway/src/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);
+}