From 79096cfdce35ee5ac4a68a04c680ef7573d0e602 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 12 Sep 2013 13:10:14 -0400 Subject: [PATCH] online count fix for anon users --- src/websockets.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/websockets.js b/src/websockets.js index 1a9d7b9e2d..fdb0911ee0 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -34,7 +34,7 @@ var SocketIO = require('socket.io').listen(global.server, { winston = require('winston'); (function(io) { - var users = {}, + var users = {}, userSockets = {}, rooms = {}; @@ -76,12 +76,14 @@ var SocketIO = require('socket.io').listen(global.server, { if(userSockets[uid].length === 0) { delete users[sessionID]; - emitOnlineUserCount(); + delete userSockets[uid]; if(uid) { io.sockets.in('global').emit('api:user.isOnline', isUserOnline(uid)); } } + emitOnlineUserCount(); + for(var roomName in rooms) { socket.leave(roomName); @@ -412,10 +414,13 @@ var SocketIO = require('socket.io').listen(global.server, { }); 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 = { - users: online.length + users: registered + anon }; io.sockets.emit('api:user.active.get', returnObj) }