summary refs log tree commit diff
path: root/gateway/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'gateway/src/util')
-rw-r--r--gateway/src/util/Constants.ts50
-rw-r--r--gateway/src/util/Heartbeat.ts11
-rw-r--r--gateway/src/util/Send.ts33
-rw-r--r--gateway/src/util/SessionUtils.ts13
-rw-r--r--gateway/src/util/WebSocket.ts22
-rw-r--r--gateway/src/util/index.ts5
6 files changed, 0 insertions, 134 deletions
diff --git a/gateway/src/util/Constants.ts b/gateway/src/util/Constants.ts
deleted file mode 100644

index 692f9028..00000000 --- a/gateway/src/util/Constants.ts +++ /dev/null
@@ -1,50 +0,0 @@ -export enum OPCODES { - Dispatch = 0, - Heartbeat = 1, - Identify = 2, - Presence_Update = 3, - Voice_State_Update = 4, - Voice_Server_Ping = 5, // ? What is opcode 5? - Resume = 6, - Reconnect = 7, - Request_Guild_Members = 8, - Invalid_Session = 9, - Hello = 10, - Heartbeat_ACK = 11, - Guild_Sync = 12, - DM_Update = 13, - Lazy_Request = 14, - Lobby_Connect = 15, - Lobby_Disconnect = 16, - Lobby_Voice_States_Update = 17, - Stream_Create = 18, - Stream_Delete = 19, - Stream_Watch = 20, - Stream_Ping = 21, - Stream_Set_Paused = 22, - Request_Application_Commands = 24, -} -export enum CLOSECODES { - Unknown_error = 4000, - Unknown_opcode, - Decode_error, - Not_authenticated, - Authentication_failed, - Already_authenticated, - Invalid_session, - Invalid_seq, - Rate_limited, - Session_timed_out, - Invalid_shard, - Sharding_required, - Invalid_API_version, - Invalid_intent, - Disallowed_intent, -} - -export interface Payload { - op: OPCODES; - d?: any; - s?: number; - t?: string; -} diff --git a/gateway/src/util/Heartbeat.ts b/gateway/src/util/Heartbeat.ts deleted file mode 100644
index f6871cfe..00000000 --- a/gateway/src/util/Heartbeat.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); -} diff --git a/gateway/src/util/Send.ts b/gateway/src/util/Send.ts deleted file mode 100644
index 2a28d8e0..00000000 --- a/gateway/src/util/Send.ts +++ /dev/null
@@ -1,33 +0,0 @@ -let erlpack: any; -try { - erlpack = require("@yukikaze-bot/erlpack"); -} catch (error) { - console.log("Missing @yukikaze-bot/erlpack, electron-based desktop clients designed for discord.com will not be able to connect!"); -} -import { Payload, WebSocket } from "@fosscord/gateway"; - -export async function Send(socket: WebSocket, data: Payload) { - if(process.env.WS_VERBOSE) - console.log(`[Websocket] Outgoing message: ${JSON.stringify(data)}`); - let buffer: Buffer | string; - if (socket.encoding === "etf") buffer = erlpack.pack(data); - // TODO: encode circular object - else if (socket.encoding === "json") buffer = JSON.stringify(data); - else return; - // TODO: compression - if (socket.deflate) { - socket.deflate.write(buffer); - socket.deflate.flush(); - return; - } - - return new Promise((res, rej) => { - if (socket.readyState !== 1) { - return rej("socket not open"); - } - socket.send(buffer, (err: any) => { - if (err) return rej(err); - return res(null); - }); - }); -} diff --git a/gateway/src/util/SessionUtils.ts b/gateway/src/util/SessionUtils.ts deleted file mode 100644
index bf854042..00000000 --- a/gateway/src/util/SessionUtils.ts +++ /dev/null
@@ -1,13 +0,0 @@ -export function genSessionId() { - return genRanHex(32); -} - -export function genVoiceToken() { - return genRanHex(16); -} - -function genRanHex(size: number) { - return [...Array(size)] - .map(() => Math.floor(Math.random() * 16).toString(16)) - .join(""); -} diff --git a/gateway/src/util/WebSocket.ts b/gateway/src/util/WebSocket.ts deleted file mode 100644
index e3313f40..00000000 --- a/gateway/src/util/WebSocket.ts +++ /dev/null
@@ -1,22 +0,0 @@ -import { Intents, Permissions } from "@fosscord/util"; -import WS from "ws"; -import { Deflate } from "zlib"; - -export interface WebSocket extends WS { - version: number; - user_id: string; - session_id: string; - encoding: "etf" | "json"; - compress?: "zlib-stream"; - shard_count?: bigint; - shard_id?: bigint; - deflate?: Deflate; - heartbeatTimeout: NodeJS.Timeout; - readyTimeout: NodeJS.Timeout; - intents: Intents; - sequence: number; - permissions: Record<string, Permissions>; - events: Record<string, Function>; - member_events: Record<string, Function>; - listen_options: any; -} diff --git a/gateway/src/util/index.ts b/gateway/src/util/index.ts deleted file mode 100644
index 0be5ecee..00000000 --- a/gateway/src/util/index.ts +++ /dev/null
@@ -1,5 +0,0 @@ -export * from "./Constants"; -export * from "./Send"; -export * from "./SessionUtils"; -export * from "./Heartbeat"; -export * from "./WebSocket";