online count fix for anon users

v1.18.x
Baris Soner Usakli 12 years ago
parent a848f82b8f
commit 79096cfdce

@ -34,7 +34,7 @@ var SocketIO = require('socket.io').listen(global.server, {
winston = require('winston'); winston = require('winston');
(function(io) { (function(io) {
var users = {}, var users = {},
userSockets = {}, userSockets = {},
rooms = {}; rooms = {};
@ -76,12 +76,14 @@ var SocketIO = require('socket.io').listen(global.server, {
if(userSockets[uid].length === 0) { if(userSockets[uid].length === 0) {
delete users[sessionID]; delete users[sessionID];
emitOnlineUserCount(); delete userSockets[uid];
if(uid) { if(uid) {
io.sockets.in('global').emit('api:user.isOnline', isUserOnline(uid)); io.sockets.in('global').emit('api:user.isOnline', isUserOnline(uid));
} }
} }
emitOnlineUserCount();
for(var roomName in rooms) { for(var roomName in rooms) {
socket.leave(roomName); socket.leave(roomName);
@ -412,10 +414,13 @@ var SocketIO = require('socket.io').listen(global.server, {
}); });
function emitOnlineUserCount() { function emitOnlineUserCount() {
var online = Object.keys(users); var anon = userSockets[0] ? userSockets[0].length : 0;
var registered = Object.keys(userSockets).length;
if(anon)
registered = registered - 1;
var returnObj = { var returnObj = {
users: online.length users: registered + anon
}; };
io.sockets.emit('api:user.active.get', returnObj) io.sockets.emit('api:user.active.get', returnObj)
} }

Loading…
Cancel
Save