diff --git a/src/rtmt/rtmt_websocket.ts b/src/rtmt/rtmt_websocket.ts index 5b0b048..14d48cf 100644 --- a/src/rtmt/rtmt_websocket.ts +++ b/src/rtmt/rtmt_websocket.ts @@ -29,7 +29,7 @@ export class RTMTWS implements RTMT { this.clients = new Map() wsServer.on("connection", (ws: WebSocket, req: Request) => { - console.log("Client Connected"); + console.log("(RTMT) Client Connected"); const regexResult = req.url.split(RegExp("\/\?userKey=")); const clientID = regexResult[1] this.clients.set(clientID, ws) @@ -39,13 +39,13 @@ export class RTMTWS implements RTMT { }) ws.on("close", (code: number, reason: string) => { - console.log("WS Closed! code : " + code + " reason : " + reason); + console.log("(RTMT) WS Closed! code : " + code + " reason : " + reason); this.clients.delete(clientID) this.onUserConnectionChange?.(clientID, false); }) ws.on("error", (err: Error) => { - console.log("WS Closed with error! error : " + err.message); + console.log("(RTMT) WS Closed with error! error : " + err.message); this.clients.delete(clientID) }) @@ -65,10 +65,10 @@ export class RTMTWS implements RTMT { if (client) { this.sendMessageInternal(client, channel, message); } else { - console.log("Client not connected!"); + console.log("(RTMT) Client not connected!"); } } else { - console.log('ws is undefined') + console.log('(RTMT) ws is undefined') } } @@ -99,7 +99,7 @@ export class RTMTWS implements RTMT { if (callback) { callback(clientID, message) } else { - console.log("Channel callback not found! " + channel); + console.log("(RTMT) Channel callback not found! " + channel); } } @@ -109,7 +109,10 @@ export class RTMTWS implements RTMT { const sendMessageInternal = this.sendMessageInternal; wsServer.clients.forEach(function each(ws) { //@ts-ignore - if (ws.isAlive === false) return ws.terminate(); + if (ws.isAlive === false) { + console.log("(RTMT) Terminated WebSocket Connection"); + return ws.terminate(); + } //@ts-ignore ws.isAlive = false; sendMessageInternal(ws, channel_ping, {}); @@ -129,7 +132,7 @@ export class RTMTWS implements RTMT { //@ts-ignore ws.isAlive = true; } - + isClientOnline(clientID: string): boolean { return this.clients.has(clientID); }