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) }