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,22 +74,26 @@ class GatewayServer extends EventEmitter {
ws.alive = true; ws.alive = true;
}); });
ws.on("close", async () => { ws.on("close", async () => {
if (ws.session.user && this.sessionCounters[ws.session.user._id] <= 1) { try {
this.inChannel(ws.channels[0], (client) => { if (ws.session.user && this.sessionCounters[ws.session.user._id] <= 1) {
console.log(client.session); this.inChannel(ws.channels[0], (client) => {
client.send(packet("EVENT_CHANNEL_MEMBERS", { console.log(client.session);
[ws.session.user._id]: { client.send(packet("EVENT_CHANNEL_MEMBERS", {
_id: ws.session.user._id, [ws.session.user._id]: {
username: ws.session.user.username, _id: ws.session.user._id,
status: 0, username: ws.session.user.username,
status_text: "Now offline" status: 0,
} status_text: "Now offline"
})); }
}); }));
});
}
this.sessionCounters[ws.session.user._id]--;
} catch(e) {
console.error("Partially failed to close socket connection", e);
} }
this.sessionCounters[ws.session.user._id]--;
if (ws.rtc) await ws.rtc.connection.close(); if (ws.rtc && ws.rtc.connection) await ws.rtc.connection.close();
}); });
ws.on("message", async (data) => { ws.on("message", async (data) => {
try { try {