diff --git a/auxilary.ts b/auxilary.ts index d1e1587..f3dfb48 100644 --- a/auxilary.ts +++ b/auxilary.ts @@ -34,7 +34,17 @@ export class SubscriptionMap { } delete(ws: WS, channel: string) { - this.getChannelList(ws)?.delete(channel); - this.getClientList(channel)?.delete(ws); + const channelList = this.getChannelList(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); + } } } diff --git a/index.ts b/index.ts index 0ebfd06..7489f02 100644 --- a/index.ts +++ b/index.ts @@ -31,7 +31,7 @@ const server = Bun.serve({ processMessage(ws, message.toString()); }, close(ws, code, reason) { - forgetConnection(ws); + forgetConnection(ws); }, }, });