fix weird error when client repeatedly connectes

This commit is contained in:
hippoz 2021-08-20 20:00:24 +03:00
parent ab878b6718
commit 6c6154c072
Signed by: hippoz
GPG key ID: 7C52899193467641

View file

@ -74,6 +74,7 @@ class GatewayServer extends EventEmitter {
ws.alive = true;
});
ws.on("close", async () => {
try {
if (ws.session.user && this.sessionCounters[ws.session.user._id] <= 1) {
this.inChannel(ws.channels[0], (client) => {
console.log(client.session);
@ -88,8 +89,11 @@ class GatewayServer extends EventEmitter {
});
}
this.sessionCounters[ws.session.user._id]--;
} catch(e) {
console.error("Partially failed to close socket connection", e);
}
if (ws.rtc) await ws.rtc.connection.close();
if (ws.rtc && ws.rtc.connection) await ws.rtc.connection.close();
});
ws.on("message", async (data) => {
try {