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,6 +74,7 @@ class GatewayServer extends EventEmitter {
|
||||||
ws.alive = true;
|
ws.alive = true;
|
||||||
});
|
});
|
||||||
ws.on("close", async () => {
|
ws.on("close", async () => {
|
||||||
|
try {
|
||||||
if (ws.session.user && this.sessionCounters[ws.session.user._id] <= 1) {
|
if (ws.session.user && this.sessionCounters[ws.session.user._id] <= 1) {
|
||||||
this.inChannel(ws.channels[0], (client) => {
|
this.inChannel(ws.channels[0], (client) => {
|
||||||
console.log(client.session);
|
console.log(client.session);
|
||||||
|
@ -88,8 +89,11 @@ class GatewayServer extends EventEmitter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.sessionCounters[ws.session.user._id]--;
|
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) => {
|
ws.on("message", async (data) => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue