From 1bce467a7ce48d32aff53350c6482ab411efea66 Mon Sep 17 00:00:00 2001 From: Robin Linus Date: Wed, 30 Dec 2015 16:50:59 +0100 Subject: [PATCH] Notify clients only if buddies change --- server/ws-server.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/server/ws-server.js b/server/ws-server.js index 2b40a3d..727285b 100644 --- a/server/ws-server.js +++ b/server/ws-server.js @@ -120,24 +120,22 @@ exports.create = function(server) { } return result; }, []); + var currState = hash(buddies.toString()); + var socket = client.socket; //protocol var msg = { buddies: buddies, isSystemEvent: true, type: 'buddies' }; - if (buddies.length) { - client.socket.send(msg); - client.notifiedEmpty = false; + if (currState !== socket.lastState) { + socket.send(msg); + socket.lastState = currState; return; } - if (!client.notifiedEmpty) { - client.notifiedEmpty = true; - client.socket.send(msg); - } }); }); } - setInterval(notifyBuddiesX, 5000); + setInterval(notifyBuddiesX, 3000); };