fix errors when unauthenticated gateway connection disconnected

This commit is contained in:
hippoz 2021-09-05 18:59:38 +03:00
parent a429348c7d
commit e53c99d749
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

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