Fixing issues after upgrading socket.io version

This commit is contained in:
Absurdon 2018-11-18 17:36:56 +01:00
parent cd648d6c6c
commit 01351c8d8b

View file

@ -23,14 +23,16 @@ var enslClient = require("../ensl/client")();
var _ = require("lodash");
module.exports = namespace => {
var refreshUsers = socket => {
var receivers = (socket !== undefined) ? [socket] : namespace.sockets;
var newCache = {};
namespace.sockets.forEach(socket => {
var user = socket._user;
var refreshUsers = socket => {
var receivers = (socket !== undefined) ? [socket] : namespace.sockets;
var newCache = {};
for(let socketid in namespace.sockets) {
let socket = namespace.sockets[socketid];
var user = socket._user;
newCache[user.id] = user;
});
}
userCache = newCache;
var users = [];
@ -41,18 +43,20 @@ module.exports = namespace => {
}
}
receivers.forEach(socket => {
socket.emit('users:update', {
for(let socketid in receivers) {
let socket = receivers[socketid];
socket.emit('users:update', {
count: users.length,
users: users,
currentUser: socket._user
});
});
});
}
};
namespace.on('connection', socket => {
refreshUsers();
socket.on('users:refresh', refreshUsers.bind(null, socket));
socket.on('users:update:profile', data => {