From 60f76a1594800da61d8015592d27077f0abd9fed Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Mon, 22 Jan 2024 03:16:47 -0500 Subject: [PATCH] Fix crashing issue --- bun.lockb | Bin 19211 -> 17584 bytes package.json | 1 - src/channel/Channel.ts | 2 +- src/util/env.ts | 7 ------- src/ws/Socket.ts | 24 +++++++++++++++++++++++- src/ws/server.ts | 25 +------------------------ 6 files changed, 25 insertions(+), 34 deletions(-) diff --git a/bun.lockb b/bun.lockb index 12f607ada34d2925402f21791130569142a8f550..dce4de86dc02db54961527896aa730d2d0fee3ea 100755 GIT binary patch delta 2557 zcmd5;X;4#F6wZ5jNCE@`q6Df4^ zS{GbVixmQjbzd13tumdubWoWQr3j*qOQ$OK+$7IBt)1z#e|l!VeD|Dl?|J8*_j2wn zt)LDrqsryJZHL##AEhpr4>f3ii@MVseRAWf$_2S~PxZcT?NfFS>Xt-tOd?-x5YsRH ztMaIUr92MDj>9Qhgv>{_!3nm=COgznGEG0UptUGHb4FI$R~*hOR2)#R!D-IO8!TLg zEI>U6*#!jjYYBf&*oDr7jYoG}uFT&$vt`C=#rPFo4dFW04iQ`lZ>wj~V810(Cc`9d z0Bqw{LbkP!aS~HWL%o%cQDSY!2tqL`WzL-A3RPThxX0x=uE&fc(PM?40SNlN=O%j8 z=t1HTuZ`Jb!?(j7>d=8{b8Mm3%8vvRj6f?J$jxHqQ+yaC7(!p*!%QT~2KFI^+d!va z2tOYy5JsL1N+#IqENW`#7KB>$!JQ8=jZWieq-n&*;+jVZI0_*)pF=pBXUW_eQ(>hP z?S5!~uxOL!^z`a*OxrmUOHImcl8-Tip1v0U$C!dRp$nu4c?9D~Ib1EXKgOiYZWcdb zQbKnGvC9xdKFV-hD26Vf(3gudd`$DqOji0L2oJK@3DYpp(WQ`B{Vi6)M3*DTu2cvT zO@kozAOsPX$@o83hvxjR%cJ>Moa3hxdIPvw8 z+2OetyKijOX3i)nUFt2wV;n~)`Sx4jK{uydg0oM^|P+6ncZ~nQ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uk}>c=+Tzot#iTa?RUJ&Yd3)i4iyt0B%YcS zD@LGx?2R2kLC5BIb<0jPoM*mYlAnq(MsL_aa_{!KyUTY1$s{iuxkyCvc4v(r7J z^D{Rc9N5wOWwY+>mJ^-JfrH}Z6NF-znvtD9KQAF|{l?9+mSrVphlfmSx?2%^s^N~U z;qB+1hhFCHe|5F6v2U5E;;q%`wfhwQmUGGAeLt55Je{J^~&QB~gKt5_A)*>)pew)%3B-!BGVgxUKyXLc|T z_`F`Q#xJ+=Fvogr#5#4v_*1kRO+3)t`Ep%(+@IwK|9GM?&P3yi<(5^_dnb40*2m2% zTJ<{I%CpJv+Tuuq<>DxLMYq_lImg&{)>}62RGpA^|ic~j0gI;h3~fH2FUw+;@5ZPO`YjLylPC4pR0Sk#xB&=toz** zi(2xfcge+_J7K$}x3%5axSH5#0rXY%U82=5nb8;LsJS!jK?xs3MI)Vo!W$Ql%qR#*J90;*u)#Ml4kMNtJ>l z7OFs{ibb^rXOXI5sd`dvLVG0osL9#em8w+N)bi8Aj!Rl;q>IQ+gcD5FsP471XY0}m z{zN0Ip~Qm3KoyI2yBM2MMXloVeO8TyujnH~^*LxYIQ$O`LsJM;bur9H6|*$*4=y4{ z7m)*Tzym^rX6w04WPr3>MZY76u{#qLmngxrP_@OPwAi)2No!(M0SH$_rewq=3L_&^qF1^)kHa%3#)MIksWGeL5@SXNz*~Ce zcpiXxfPcU<3h2_l@pGD2WK0fBnTQR9Y#bR6scVU!(); + +export function findSocketByPartID(id: string) { + for (const socket of socketsBySocketID.values()) { + if (socket.getParticipantID() == id) return socket; + } +} + +export function findSocketByUserID(_id: string) { + for (const socket of socketsBySocketID.values()) { + // logger.debug("User ID:", socket.getUserID()); + if (socket.getUserID() == _id) return socket; + } +} + +export function findSocketByIP(ip: string) { + for (const socket of socketsBySocketID.values()) { + if (socket.getIP() == ip) { + return socket; + } + } +} diff --git a/src/ws/server.ts b/src/ws/server.ts index f12d3c4..1fe877d 100644 --- a/src/ws/server.ts +++ b/src/ws/server.ts @@ -4,35 +4,12 @@ import fs from "fs"; import path from "path"; import { handleMessage } from "./message"; import { decoder } from "../util/helpers"; -import { Socket } from "./Socket"; +import { Socket, socketsBySocketID } from "./Socket"; import { serve, file } from "bun"; import env from "../util/env"; const logger = new Logger("WebSocket Server"); -export const socketsBySocketID = new Map(); - -export function findSocketByPartID(id: string) { - for (const socket of socketsBySocketID.values()) { - if (socket.getParticipantID() == id) return socket; - } -} - -export function findSocketByUserID(_id: string) { - for (const socket of socketsBySocketID.values()) { - // logger.debug("User ID:", socket.getUserID()); - if (socket.getUserID() == _id) return socket; - } -} - -export function findSocketByIP(ip: string) { - for (const socket of socketsBySocketID.values()) { - if (socket.getIP() == ip) { - return socket; - } - } -} - export const app = Bun.serve({ port: env.PORT, hostname: "0.0.0.0",