From 7bd0a2004c9d7f1c59b510a5462b82c4b0a0ce7a Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 2 Oct 2021 15:12:47 +0200 Subject: :art: restructure gateway --- gateway/src/util/Heartbeat.ts | 11 +++++++++++ gateway/src/util/WebSocket.ts | 1 - gateway/src/util/index.ts | 2 +- gateway/src/util/setHeartbeat.ts | 11 ----------- 4 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 gateway/src/util/Heartbeat.ts delete mode 100644 gateway/src/util/setHeartbeat.ts (limited to 'gateway/src/util') 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); +} diff --git a/gateway/src/util/WebSocket.ts b/gateway/src/util/WebSocket.ts index b80265a7..49626b2a 100644 --- a/gateway/src/util/WebSocket.ts +++ b/gateway/src/util/WebSocket.ts @@ -1,7 +1,6 @@ import { Intents, Permissions } from "@fosscord/util"; import WS from "ws"; import { Deflate } from "zlib"; -import { Channel } from "amqplib"; export interface WebSocket extends WS { version: number; diff --git a/gateway/src/util/index.ts b/gateway/src/util/index.ts index 27af5813..0be5ecee 100644 --- a/gateway/src/util/index.ts +++ b/gateway/src/util/index.ts @@ -1,5 +1,5 @@ export * from "./Constants"; export * from "./Send"; export * from "./SessionUtils"; -export * from "./setHeartbeat"; +export * from "./Heartbeat"; export * from "./WebSocket"; diff --git a/gateway/src/util/setHeartbeat.ts b/gateway/src/util/setHeartbeat.ts deleted file mode 100644 index f6871cfe..00000000 --- a/gateway/src/util/setHeartbeat.ts +++ /dev/null @@ -1,11 +0,0 @@ -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