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 untrusted user who does not match committer: hippoz
GPG key ID: 7C52899193467641

View file

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