forked from hippoz/brainlet
fix weird error when client repeatedly connectes
This commit is contained in:
parent
ab878b6718
commit
6c6154c072
1 changed files with 18 additions and 14 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue