add rtmt log

This commit is contained in:
Halit Aksoy 2022-09-07 21:13:16 +03:00
parent 8701c3d2f0
commit b8a85b1a98

View File

@ -29,7 +29,7 @@ export class RTMTWS implements RTMT {
this.clients = new Map<string, WebSocket>() this.clients = new Map<string, WebSocket>()
wsServer.on("connection", (ws: WebSocket, req: Request) => { wsServer.on("connection", (ws: WebSocket, req: Request) => {
console.log("Client Connected"); console.log("(RTMT) Client Connected");
const regexResult = req.url.split(RegExp("\/\?userKey=")); const regexResult = req.url.split(RegExp("\/\?userKey="));
const clientID = regexResult[1] const clientID = regexResult[1]
this.clients.set(clientID, ws) this.clients.set(clientID, ws)
@ -39,13 +39,13 @@ export class RTMTWS implements RTMT {
}) })
ws.on("close", (code: number, reason: string) => { 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.clients.delete(clientID)
this.onUserConnectionChange?.(clientID, false); this.onUserConnectionChange?.(clientID, false);
}) })
ws.on("error", (err: Error) => { 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) this.clients.delete(clientID)
}) })
@ -65,10 +65,10 @@ export class RTMTWS implements RTMT {
if (client) { if (client) {
this.sendMessageInternal(client, channel, message); this.sendMessageInternal(client, channel, message);
} else { } else {
console.log("Client not connected!"); console.log("(RTMT) Client not connected!");
} }
} else { } else {
console.log('ws is undefined') console.log('(RTMT) ws is undefined')
} }
} }
@ -99,7 +99,7 @@ export class RTMTWS implements RTMT {
if (callback) { if (callback) {
callback(clientID, message) callback(clientID, message)
} else { } 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; const sendMessageInternal = this.sendMessageInternal;
wsServer.clients.forEach(function each(ws) { wsServer.clients.forEach(function each(ws) {
//@ts-ignore //@ts-ignore
if (ws.isAlive === false) return ws.terminate(); if (ws.isAlive === false) {
console.log("(RTMT) Terminated WebSocket Connection");
return ws.terminate();
}
//@ts-ignore //@ts-ignore
ws.isAlive = false; ws.isAlive = false;
sendMessageInternal(ws, channel_ping, {}); sendMessageInternal(ws, channel_ping, {});