diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sockets.js | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/sockets.js b/lib/sockets.js index fcca9386..1ed18610 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -34,15 +34,17 @@ emit = (username, type, data) => { }; broadcast = (type, data) => { + const sent = []; for (const username in sockets) { for (const id in sockets[username]) { const ws = sockets[username][id]; ws.send(JSON.stringify({ type, data })); + sent.push(ws.id); } } Object.values(all).map(ws => { - ws.send(JSON.stringify({ type, data })); + if (!sent.includes(ws.id)) ws.send(JSON.stringify({ type, data })); }); }; @@ -66,6 +68,7 @@ setInterval(() => { wss.on("connection", function(ws, req) { const id = uuidv4(); + ws.id = id; ws.beats = 0; ws.send(JSON.stringify({ type: "connected", data: id })); all[id] = ws; |
