From acf3c226b37b02076aa13eb2f249680d30639ed2 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Wed, 22 Jul 2015 16:44:19 +0100 Subject: [PATCH] Only show unique gatherers --- config/socketio.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/config/socketio.js b/config/socketio.js index c893a14..0560975 100644 --- a/config/socketio.js +++ b/config/socketio.js @@ -6,6 +6,8 @@ var enslClient = require(path.join(__dirname, "../lib/ensl/client"))(); var chatController = require(path.join(__dirname, "../lib/chat/controller")); var winston = require("winston"); +var gathererCache = {}; + module.exports = function (io) { var root = io.of("/"); var authorised = io.of("/authorised"); @@ -31,11 +33,24 @@ module.exports = function (io) { var refreshGatherers = function (socket) { var receiver = (socket !== undefined) ? socket : root; + var newCache = {}; + root.sockets.forEach(function (socket) { + var user = socket._user; + newCache[user.id] = user; + }); + gathererCache = newCache; + + var gatherers = []; + + for (var id in gathererCache) { + if (gathererCache.hasOwnProperty(id)) { + gatherers.push(gathererCache[id]); + } + } + receiver.emit('gatherCount', { count: root.sockets.length, - gatherers: root.sockets.map(function (socket) { - return socket._user - }) + gatherers: gatherers }); };