diff options
| author | Adam Soltys <[email protected]> | 2020-10-08 19:14:50 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2020-10-09 10:06:01 -0700 |
| commit | 4487ee2d68a62278fbadbe8f018cc6cd9a08062e (patch) | |
| tree | 245451228dc650ea03a48ba849cb3a7a686d20ed /lib | |
| parent | c5af72c886a8571bd1da6aca577a25fdfce144ca (diff) | |
| download | coinos-server-4487ee2d68a62278fbadbe8f018cc6cd9a08062e.tar.gz coinos-server-4487ee2d68a62278fbadbe8f018cc6cd9a08062e.zip | |
prevent double broadcast
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; |
