From 86faf72ffcc0006d48e95e93dd7ce115cb70cad0 Mon Sep 17 00:00:00 2001 From: sophie Date: Sat, 27 Apr 2024 15:10:55 +0300 Subject: [PATCH] use map instead --- src/build.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/build.ts b/src/build.ts index 07729c5..bfa3fff 100644 --- a/src/build.ts +++ b/src/build.ts @@ -28,19 +28,14 @@ if(argv[0] == "--dev") { const scriptName = Math.random().toFixed(10).replace("0.","") const wss = new WebSocketServer({ port: 8081 }); - let allConnections: any[] = []; - + let allConnections = new Map(); wss.on('connection', function connection(ws) { - //@ts-ignore - ws.id = Math.random(); - //@ts-ignore - - allConnections.push(ws); + const id = Math.random(); + allConnections.set(id, ws as any); ws.on('error', console.error); ws.on("close", () => { - //@ts-ignore - allConnections = allConnections.filter(z => z.id != ws.id); + allConnections.delete(id); }) }); const server = new Server(