in case more than 256 connections

This commit is contained in:
Lamp 2021-12-02 23:34:17 -08:00
parent 42eb01257b
commit 3537634d17

@ -33,6 +33,7 @@ wss.on("connection", (ws, req) => {
}
let t = Array.from(wss.clients).map(ws => ws.user.id);
for (let i = 0; i < 256; i++) if (!t.includes(i)) { ws.user = i; break; }
if (!ws.user.id) return ws.close();
console.log("join", ws.user);