summary refs log tree commit diff
path: root/gateway/src
diff options
context:
space:
mode:
Diffstat (limited to 'gateway/src')
-rw-r--r--gateway/src/events/Close.ts2
-rw-r--r--gateway/src/events/Connection.ts29
-rw-r--r--gateway/src/events/Message.ts14
-rw-r--r--gateway/src/index.ts3
-rw-r--r--gateway/src/listener/listener.ts39
-rw-r--r--gateway/src/opcodes/Heartbeat.ts5
-rw-r--r--gateway/src/opcodes/Identify.ts73
-rw-r--r--gateway/src/opcodes/LazyRequest.ts5
-rw-r--r--gateway/src/opcodes/PresenceUpdate.ts3
-rw-r--r--gateway/src/opcodes/RequestGuildMembers.ts4
-rw-r--r--gateway/src/opcodes/Resume.ts5
-rw-r--r--gateway/src/opcodes/VoiceStateUpdate.ts44
-rw-r--r--gateway/src/opcodes/index.ts4
-rw-r--r--gateway/src/opcodes/instanceOf.ts3
-rw-r--r--gateway/src/schema/Identify.ts1
-rw-r--r--gateway/src/util/Send.ts8
-rw-r--r--gateway/src/util/WebSocket.ts7
-rw-r--r--gateway/src/util/index.ts5
-rw-r--r--gateway/src/util/setHeartbeat.ts2
19 files changed, 152 insertions, 104 deletions
diff --git a/gateway/src/events/Close.ts b/gateway/src/events/Close.ts

index 2f274ec4..1299ad5c 100644 --- a/gateway/src/events/Close.ts +++ b/gateway/src/events/Close.ts
@@ -1,4 +1,4 @@ -import WebSocket from "../util/WebSocket"; +import { WebSocket } from "@fosscord/gateway"; import { Message } from "./Message"; import { Session } from "@fosscord/util"; diff --git a/gateway/src/events/Connection.ts b/gateway/src/events/Connection.ts
index b3c94eaf..85f92b77 100644 --- a/gateway/src/events/Connection.ts +++ b/gateway/src/events/Connection.ts
@@ -1,23 +1,31 @@ -import WebSocket, { Server } from "../util/WebSocket"; +import WS from "ws"; +import { + setHeartbeat, + Send, + CLOSECODES, + OPCODES, + WebSocket, +} from "@fosscord/gateway"; import { IncomingMessage } from "http"; import { Close } from "./Close"; import { Message } from "./Message"; -import { setHeartbeat } from "../util/setHeartbeat"; -import { Send } from "../util/Send"; -import { CLOSECODES, OPCODES } from "../util/Constants"; import { createDeflate } from "zlib"; import { URL } from "url"; import { Session } from "@fosscord/util"; var erlpack: any; try { - erlpack = require("erlpack"); + erlpack = require("@yukikaze-bot/erlpack"); } catch (error) {} // TODO: check rate limit // TODO: specify rate limit in config // TODO: check msg max size -export async function Connection(this: Server, socket: WebSocket, request: IncomingMessage) { +export async function Connection( + this: WS.Server, + socket: WebSocket, + request: IncomingMessage +) { try { socket.on("close", Close); // @ts-ignore @@ -27,18 +35,21 @@ export async function Connection(this: Server, socket: WebSocket, request: Incom // @ts-ignore socket.encoding = searchParams.get("encoding") || "json"; if (!["json", "etf"].includes(socket.encoding)) { - if (socket.encoding === "etf" && erlpack) throw new Error("Erlpack is not installed: 'npm i -D erlpack'"); + if (socket.encoding === "etf" && erlpack) + throw new Error("Erlpack is not installed: 'npm i -D erlpack'"); return socket.close(CLOSECODES.Decode_error); } // @ts-ignore socket.version = Number(searchParams.get("version")) || 8; - if (socket.version != 8) return socket.close(CLOSECODES.Invalid_API_version); + if (socket.version != 8) + return socket.close(CLOSECODES.Invalid_API_version); // @ts-ignore socket.compress = searchParams.get("compress") || ""; if (socket.compress) { - if (socket.compress !== "zlib-stream") return socket.close(CLOSECODES.Decode_error); + if (socket.compress !== "zlib-stream") + return socket.close(CLOSECODES.Decode_error); socket.deflate = createDeflate({ chunkSize: 65535 }); socket.deflate.on("data", (chunk) => socket.send(chunk)); } diff --git a/gateway/src/events/Message.ts b/gateway/src/events/Message.ts
index a8bf5d78..1f1c4f72 100644 --- a/gateway/src/events/Message.ts +++ b/gateway/src/events/Message.ts
@@ -1,10 +1,9 @@ -import WebSocket, { Data } from "../util/WebSocket"; +import { WebSocket, Payload, CLOSECODES, OPCODES } from "@fosscord/gateway"; var erlpack: any; try { - erlpack = require("erlpack"); + erlpack = require("@yukikaze-bot/erlpack"); } catch (error) {} import OPCodeHandlers from "../opcodes"; -import { Payload, CLOSECODES, OPCODES } from "../util/Constants"; import { instanceOf, Tuple } from "lambert-server"; import { check } from "../opcodes/instanceOf"; import WS from "ws"; @@ -20,8 +19,10 @@ export async function Message(this: WebSocket, buffer: WS.Data) { // TODO: compression var data: Payload; - if (this.encoding === "etf" && buffer instanceof Buffer) data = erlpack.unpack(buffer); - else if (this.encoding === "json" && typeof buffer === "string") data = JSON.parse(buffer); + if (this.encoding === "etf" && buffer instanceof Buffer) + data = erlpack.unpack(buffer); + else if (this.encoding === "json" && typeof buffer === "string") + data = JSON.parse(buffer); else return; check.call(this, PayloadSchema, data); @@ -41,6 +42,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) { return await OPCodeHandler.call(this, data); } catch (error) { console.error(error); - if (!this.CLOSED && this.CLOSING) return this.close(CLOSECODES.Unknown_error); + if (!this.CLOSED && this.CLOSING) + return this.close(CLOSECODES.Unknown_error); } } diff --git a/gateway/src/index.ts b/gateway/src/index.ts
index 7513bd2f..d77ce931 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts
@@ -1 +1,4 @@ export * from "./Server"; +export * from "./util/"; +export * from "./opcodes/"; +export * from "./listener/listener"; diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts
index 0b6fa50c..0fa6bb08 100644 --- a/gateway/src/listener/listener.ts +++ b/gateway/src/listener/listener.ts
@@ -9,13 +9,10 @@ import { ListenEventOpts, Member, } from "@fosscord/util"; -import { OPCODES } from "../util/Constants"; -import { Send } from "../util/Send"; -import WebSocket from "../util/WebSocket"; +import { OPCODES, WebSocket, Send } from "@fosscord/gateway"; import "missing-native-js-functions"; import { Channel as AMQChannel } from "amqplib"; -import { In, Like } from "../../../util/node_modules/typeorm"; -import { Recipient } from "../../../util/dist/entities/Recipient"; +import { Recipient } from "@fosscord/util"; // TODO: close connection on Invalidated Token // TODO: check intent @@ -26,16 +23,16 @@ import { Recipient } from "../../../util/dist/entities/Recipient"; // TODO: use already queried guilds/channels of Identify and don't fetch them again export async function setupListener(this: WebSocket) { - const members = await Member.find({ id: this.user_id }); - const guild_ids = members.map((x) => x.guild_id); - const user = await User.findOneOrFail({ id: this.user_id }); + const members = await Member.find({ + where: { id: this.user_id }, + relations: ["guild", "guild.channels"], + }); + const guilds = members.map((x) => x.guild); const recipients = await Recipient.find({ - where: { user_id: this.user_id }, + where: { user_id: this.user_id, closed: false }, relations: ["channel"], }); - const channels = await Channel.find({ guild_id: In(guild_ids) }); const dm_channels = recipients.map((x) => x.channel); - const guild_channels = channels.filter((x) => x.guild_id); const opts: { acknowledge: boolean; channel?: AMQChannel } = { acknowledge: true, @@ -54,21 +51,23 @@ export async function setupListener(this: WebSocket) { this.events[channel.id] = await listenEvent(channel.id, consumer, opts); } - for (const guild of guild_ids) { + for (const guild of guilds) { // contains guild and dm channels - getPermission(this.user_id, guild) + getPermission(this.user_id, guild.id) .then(async (x) => { - this.permissions[guild] = x; + this.permissions[guild.id] = x; this.listeners; - this.events[guild] = await listenEvent(guild, consumer, opts); + this.events[guild.id] = await listenEvent( + guild.id, + consumer, + opts + ); - for (const channel of guild_channels.filter( - (c) => c.guild_id === guild - )) { + for (const channel of guild.channels) { if ( x - .overwriteChannel(channel.permission_overwrites) + .overwriteChannel(channel.permission_overwrites!) .has("VIEW_CHANNEL") ) { this.events[channel.id] = await listenEvent( @@ -114,7 +113,7 @@ async function consume(this: WebSocket, opts: EventOpts) { .has("VIEW_CHANNEL") ) return; - // TODO: check if user has permission to channel + //No break needed here, we need to call the listenEvent function below case "GUILD_CREATE": this.events[id] = await listenEvent(id, consumer, listenOpts); break; diff --git a/gateway/src/opcodes/Heartbeat.ts b/gateway/src/opcodes/Heartbeat.ts
index 015257b9..46caee56 100644 --- a/gateway/src/opcodes/Heartbeat.ts +++ b/gateway/src/opcodes/Heartbeat.ts
@@ -1,7 +1,4 @@ -import { CLOSECODES, Payload } from "../util/Constants"; -import { Send } from "../util/Send"; -import { setHeartbeat } from "../util/setHeartbeat"; -import WebSocket from "../util/WebSocket"; +import { Payload, Send, setHeartbeat, WebSocket } from "@fosscord/gateway"; export async function onHeartbeat(this: WebSocket, data: Payload) { // TODO: validate payload diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts
index 95db7f3d..a58583ee 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts
@@ -1,5 +1,10 @@ -import { CLOSECODES, Payload, OPCODES } from "../util/Constants"; -import WebSocket from "../util/WebSocket"; +import { + WebSocket, + CLOSECODES, + Payload, + OPCODES, + genSessionId, +} from "@fosscord/gateway"; import { Channel, checkToken, @@ -14,15 +19,16 @@ import { dbConnection, PublicMemberProjection, PublicMember, + ChannelType, + PublicUser, } from "@fosscord/util"; import { setupListener } from "../listener/listener"; import { IdentifySchema } from "../schema/Identify"; -import { Send } from "../util/Send"; +import { Send } from "@fosscord/gateway/util/Send"; // import experiments from "./experiments.json"; const experiments: any = []; import { check } from "./instanceOf"; -import { Recipient } from "../../../util/dist/entities/Recipient"; -import { genSessionId } from "../util/SessionUtils"; +import { Recipient } from "@fosscord/util"; // TODO: bot sharding // TODO: check priviliged intents @@ -48,15 +54,17 @@ export async function onIdentify(this: WebSocket, data: Payload) { this.shard_id = identify.shard[0]; this.shard_count = identify.shard[1]; if ( - !this.shard_count || - !this.shard_id || + this.shard_count == null || + this.shard_id == null || this.shard_id >= this.shard_count || this.shard_id < 0 || this.shard_count <= 0 ) { + console.log(identify.shard); return this.close(CLOSECODES.Invalid_shard); } } + var users: PublicUser[] = []; const members = await Member.find({ where: { id: this.user_id }, @@ -84,13 +92,42 @@ export async function onIdentify(this: WebSocket, data: Payload) { const user_guild_settings_entries = members.map((x) => x.settings); const recipients = await Recipient.find({ - where: { user_id: this.user_id }, - relations: ["channel", "channel.recipients"], + where: { user_id: this.user_id, closed: false }, + relations: ["channel", "channel.recipients", "channel.recipients.user"], + // TODO: public user selection + }); + const channels = recipients.map((x) => { + // @ts-ignore + x.channel.recipients = x.channel.recipients?.map((x) => x.user); + //TODO is this needed? check if users in group dm that are not friends are sent in the READY event + //users = users.concat(x.channel.recipients); + if (x.channel.isDm()) { + x.channel.recipients = x.channel.recipients!.filter( + (x) => x.id !== this.user_id + ); + } + return x.channel; + }); + const user = await User.findOneOrFail({ + where: { id: this.user_id }, + relations: ["relationships", "relationships.to"], }); - const channels = recipients.map((x) => x.channel); - const user = await User.findOneOrFail({ id: this.user_id }); if (!user) return this.close(CLOSECODES.Authentication_failed); + for (let relation of user.relationships) { + const related_user = relation.to; + const public_related_user = { + username: related_user.username, + discriminator: related_user.discriminator, + id: related_user.id, + public_flags: related_user.public_flags, + avatar: related_user.avatar, + bot: related_user.bot, + bio: related_user.bio, + }; + users.push(public_related_user); + } + const session_id = genSessionId(); this.session_id = session_id; //Set the session of the WebSocket object const session = new Session({ @@ -108,16 +145,6 @@ export async function onIdentify(this: WebSocket, data: Payload) { //We save the session and we delete it when the websocket is closed await session.save(); - const public_user = { - username: user.username, - discriminator: user.discriminator, - id: user.id, - public_flags: user.public_flags, - avatar: user.avatar, - bot: user.bot, - bio: user.bio, - }; - const privateUser = { avatar: user.avatar, mobile: user.mobile, @@ -154,7 +181,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { }), guild_experiments: [], // TODO geo_ordered_rtc_regions: [], // TODO - relationships: user.relationships, + relationships: user.relationships.map((x) => x.toPublicRelationship()), read_state: { // TODO entries: [], @@ -180,7 +207,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { // @ts-ignore experiments: experiments, // TODO guild_join_requests: [], // TODO what is this? - users: [public_user].unique(), // TODO + users: users.unique(), merged_members: merged_members, // shard // TODO: only for bots sharding // application // TODO for applications diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts
index b7ee9a96..db00157f 100644 --- a/gateway/src/opcodes/LazyRequest.ts +++ b/gateway/src/opcodes/LazyRequest.ts
@@ -2,13 +2,10 @@ import { getPermission, Member, PublicMemberProjection, - PublicUserProjection, Role, } from "@fosscord/util"; import { LazyRequest } from "../schema/LazyRequest"; -import { OPCODES, Payload } from "../util/Constants"; -import { Send } from "../util/Send"; -import WebSocket from "../util/WebSocket"; +import { WebSocket, Send, OPCODES, Payload } from "@fosscord/gateway"; import { check } from "./instanceOf"; import "missing-native-js-functions"; diff --git a/gateway/src/opcodes/PresenceUpdate.ts b/gateway/src/opcodes/PresenceUpdate.ts
index 3760f8a3..53d7b9d2 100644 --- a/gateway/src/opcodes/PresenceUpdate.ts +++ b/gateway/src/opcodes/PresenceUpdate.ts
@@ -1,5 +1,4 @@ -import { CLOSECODES, Payload } from "../util/Constants"; -import WebSocket from "../util/WebSocket"; +import { WebSocket, Payload } from "@fosscord/gateway"; export function onPresenceUpdate(this: WebSocket, data: Payload) { // return this.close(CLOSECODES.Unknown_error); diff --git a/gateway/src/opcodes/RequestGuildMembers.ts b/gateway/src/opcodes/RequestGuildMembers.ts
index 2701d978..b80721dc 100644 --- a/gateway/src/opcodes/RequestGuildMembers.ts +++ b/gateway/src/opcodes/RequestGuildMembers.ts
@@ -1,6 +1,4 @@ -import { CLOSECODES, Payload } from "../util/Constants"; - -import WebSocket from "../util/WebSocket"; +import { Payload, WebSocket } from "@fosscord/gateway"; export function onRequestGuildMembers(this: WebSocket, data: Payload) { // return this.close(CLOSECODES.Unknown_error); diff --git a/gateway/src/opcodes/Resume.ts b/gateway/src/opcodes/Resume.ts
index 4efde9b0..398cce25 100644 --- a/gateway/src/opcodes/Resume.ts +++ b/gateway/src/opcodes/Resume.ts
@@ -1,7 +1,4 @@ -import { CLOSECODES, Payload } from "../util/Constants"; -import { Send } from "../util/Send"; - -import WebSocket from "../util/WebSocket"; +import { WebSocket, Payload, Send } from "@fosscord/gateway"; export async function onResume(this: WebSocket, data: Payload) { console.log("Got Resume -> cancel not implemented"); diff --git a/gateway/src/opcodes/VoiceStateUpdate.ts b/gateway/src/opcodes/VoiceStateUpdate.ts
index 95a01608..084c5766 100644 --- a/gateway/src/opcodes/VoiceStateUpdate.ts +++ b/gateway/src/opcodes/VoiceStateUpdate.ts
@@ -1,9 +1,16 @@ import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdateSchema"; -import { Payload } from "../util/Constants"; -import WebSocket from "../util/WebSocket"; +import { Payload, WebSocket, genVoiceToken } from "@fosscord/gateway"; import { check } from "./instanceOf"; -import { Config, emitEvent, Guild, Member, Region, VoiceServerUpdateEvent, VoiceState, VoiceStateUpdateEvent } from "@fosscord/util"; -import { genVoiceToken } from "../util/SessionUtils"; +import { + Config, + emitEvent, + Guild, + Member, + Region, + VoiceServerUpdateEvent, + VoiceState, + VoiceStateUpdateEvent, +} from "@fosscord/util"; // TODO: check if a voice server is setup // Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not. @@ -14,21 +21,27 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { let voiceState: VoiceState; try { voiceState = await VoiceState.findOneOrFail({ - where: { user_id: this.user_id } + where: { user_id: this.user_id }, }); - if (voiceState.session_id !== this.session_id && body.channel_id === null) { + if ( + voiceState.session_id !== this.session_id && + body.channel_id === null + ) { //Should we also check guild_id === null? //changing deaf or mute on a client that's not the one with the same session of the voicestate in the database should be ignored return; } //If a user change voice channel between guild we should send a left event first - if (voiceState.guild_id !== body.guild_id && voiceState.session_id === this.session_id) { + if ( + voiceState.guild_id !== body.guild_id && + voiceState.session_id === this.session_id + ) { await emitEvent({ event: "VOICE_STATE_UPDATE", data: { ...voiceState, channel_id: null }, guild_id: voiceState.guild_id, - }) + }); } //The event send by Discord's client on channel leave has both guild_id and channel_id as null @@ -50,10 +63,11 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { voiceState.member = await Member.findOneOrFail({ where: { id: voiceState.user_id, guild_id: voiceState.guild_id }, relations: ["user", "roles"], - }) + }); //If the session changed we generate a new token - if (voiceState.session_id !== this.session_id) voiceState.token = genVoiceToken(); + if (voiceState.session_id !== this.session_id) + voiceState.token = genVoiceToken(); voiceState.session_id = this.session_id; const { id, ...newObj } = voiceState; @@ -69,13 +83,17 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) { //If it's null it means that we are leaving the channel and this event is not needed if (voiceState.channel_id !== null) { - const guild = await Guild.findOne({ id: voiceState.guild_id }) + const guild = await Guild.findOne({ id: voiceState.guild_id }); const regions = Config.get().regions; let guildRegion: Region; if (guild && guild.region) { - guildRegion = regions.available.filter(r => (r.id === guild.region))[0] + guildRegion = regions.available.filter( + (r) => r.id === guild.region + )[0]; } else { - guildRegion = regions.available.filter(r => (r.id === regions.default))[0] + guildRegion = regions.available.filter( + (r) => r.id === regions.default + )[0]; } await emitEvent({ diff --git a/gateway/src/opcodes/index.ts b/gateway/src/opcodes/index.ts
index fa57f568..027739db 100644 --- a/gateway/src/opcodes/index.ts +++ b/gateway/src/opcodes/index.ts
@@ -1,5 +1,4 @@ -import { Payload } from "../util/Constants"; -import WebSocket from "../util/WebSocket"; +import { WebSocket, Payload } from "@fosscord/gateway"; import { onHeartbeat } from "./Heartbeat"; import { onIdentify } from "./Identify"; import { onLazyRequest } from "./LazyRequest"; @@ -21,5 +20,6 @@ export default { 8: onRequestGuildMembers, // 9: Invalid Session // 10: Hello + // 13: Dm_update 14: onLazyRequest, }; diff --git a/gateway/src/opcodes/instanceOf.ts b/gateway/src/opcodes/instanceOf.ts
index c4ee5ee6..37d513ad 100644 --- a/gateway/src/opcodes/instanceOf.ts +++ b/gateway/src/opcodes/instanceOf.ts
@@ -1,6 +1,5 @@ import { instanceOf } from "lambert-server"; -import { CLOSECODES } from "../util/Constants"; -import WebSocket from "../util/WebSocket"; +import { WebSocket, CLOSECODES } from "@fosscord/gateway"; export function check(this: WebSocket, schema: any, data: any) { try { diff --git a/gateway/src/schema/Identify.ts b/gateway/src/schema/Identify.ts
index 0835ddc7..6054f2e8 100644 --- a/gateway/src/schema/Identify.ts +++ b/gateway/src/schema/Identify.ts
@@ -43,6 +43,7 @@ export const IdentifySchema = { $user_guild_settings_version: Number, }, $v: Number, + $version: Number, }; export interface IdentifySchema { diff --git a/gateway/src/util/Send.ts b/gateway/src/util/Send.ts
index be25ac4f..4defa898 100644 --- a/gateway/src/util/Send.ts +++ b/gateway/src/util/Send.ts
@@ -1,10 +1,8 @@ var erlpack: any; try { - erlpack = require("erlpack"); + erlpack = require("@yukikaze-bot/erlpack"); } catch (error) {} -import { Payload } from "../util/Constants"; - -import WebSocket from "./WebSocket"; +import { Payload, WebSocket } from "@fosscord/gateway"; export async function Send(socket: WebSocket, data: Payload) { let buffer: Buffer | string; @@ -20,7 +18,7 @@ export async function Send(socket: WebSocket, data: Payload) { } return new Promise((res, rej) => { - socket.send(buffer, (err) => { + socket.send(buffer, (err: any) => { if (err) return rej(err); return res(null); }); diff --git a/gateway/src/util/WebSocket.ts b/gateway/src/util/WebSocket.ts
index 2c763743..b80265a7 100644 --- a/gateway/src/util/WebSocket.ts +++ b/gateway/src/util/WebSocket.ts
@@ -1,9 +1,9 @@ import { Intents, Permissions } from "@fosscord/util"; -import WS, { Server, Data } from "ws"; +import WS from "ws"; import { Deflate } from "zlib"; import { Channel } from "amqplib"; -interface WebSocket extends WS { +export interface WebSocket extends WS { version: number; user_id: string; session_id: string; @@ -19,6 +19,3 @@ interface WebSocket extends WS { permissions: Record<string, Permissions>; events: Record<string, Function>; } - -export default WebSocket; -export { Server, Data }; diff --git a/gateway/src/util/index.ts b/gateway/src/util/index.ts new file mode 100644
index 00000000..27af5813 --- /dev/null +++ b/gateway/src/util/index.ts
@@ -0,0 +1,5 @@ +export * from "./Constants"; +export * from "./Send"; +export * from "./SessionUtils"; +export * from "./setHeartbeat"; +export * from "./WebSocket"; diff --git a/gateway/src/util/setHeartbeat.ts b/gateway/src/util/setHeartbeat.ts
index 9f88b481..f6871cfe 100644 --- a/gateway/src/util/setHeartbeat.ts +++ b/gateway/src/util/setHeartbeat.ts
@@ -1,5 +1,5 @@ import { CLOSECODES } from "./Constants"; -import WebSocket from "./WebSocket"; +import { WebSocket } from "./WebSocket"; // TODO: make heartbeat timeout configurable export function setHeartbeat(socket: WebSocket) {