Only show unique gatherers

This commit is contained in:
Chris Blanchard 2015-07-22 16:44:19 +01:00
parent fb2ca2a4f3
commit acf3c226b3

View file

@ -6,6 +6,8 @@ var enslClient = require(path.join(__dirname, "../lib/ensl/client"))();
var chatController = require(path.join(__dirname, "../lib/chat/controller")); var chatController = require(path.join(__dirname, "../lib/chat/controller"));
var winston = require("winston"); var winston = require("winston");
var gathererCache = {};
module.exports = function (io) { module.exports = function (io) {
var root = io.of("/"); var root = io.of("/");
var authorised = io.of("/authorised"); var authorised = io.of("/authorised");
@ -31,11 +33,24 @@ module.exports = function (io) {
var refreshGatherers = function (socket) { var refreshGatherers = function (socket) {
var receiver = (socket !== undefined) ? socket : root; 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', { receiver.emit('gatherCount', {
count: root.sockets.length, count: root.sockets.length,
gatherers: root.sockets.map(function (socket) { gatherers: gatherers
return socket._user
})
}); });
}; };