clean disconnected sockets

This commit is contained in:
marlonerler
2024-07-04 18:18:44 +02:00
parent 57d484a0e6
commit dc5550b376
2 changed files with 13 additions and 3 deletions
+12 -2
View File
@@ -34,7 +34,17 @@ export class SubscriptionMap {
} }
delete(ws: WS, channel: string) { delete(ws: WS, channel: string) {
this.getChannelList(ws)?.delete(channel); const channelList = this.getChannelList(ws);
this.getClientList(channel)?.delete(ws); const clientList = this.getClientList(channel);
channelList?.delete(channel);
if (channelList?.size == 0) {
this.channelsPerClient.delete(ws);
}
clientList?.delete(ws);
if (clientList?.size == 0) {
this.clientsPerChannel.delete(channel);
}
} }
} }
+1 -1
View File
@@ -31,7 +31,7 @@ const server = Bun.serve({
processMessage(ws, message.toString()); processMessage(ws, message.toString());
}, },
close(ws, code, reason) { close(ws, code, reason) {
forgetConnection(ws); forgetConnection(ws);
}, },
}, },
}); });