Remove socket on close
- Remove socket on close
- Remove id when empty socket list
Change-Id: Ic6b3bc2778497fc9b2217bc940c0f705f42d2cca
diff --git a/server/src/ws.ts b/server/src/ws.ts
index 58cd3db..3ac1bcd 100644
--- a/server/src/ws.ts
+++ b/server/src/ws.ts
@@ -62,6 +62,18 @@
}
}
});
+
+ ws.on('close', () => {
+ log.info('Connection close', accountId);
+ const accountSockets = this.sockets.get(accountId);
+ const index = accountSockets?.indexOf(ws);
+ if (index !== undefined) {
+ accountSockets?.splice(index, 1);
+ if (accountSockets?.length === 0) {
+ this.sockets.delete(accountId);
+ }
+ }
+ });
});
return (request: IncomingMessage, socket: Duplex, head: Buffer) => {