From 83cb9162644a425000cd3c653a57c8e7b157486b Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 13 Jan 2016 16:15:49 +0200 Subject: [PATCH] closes #4038 --- src/socket.io/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/socket.io/index.js b/src/socket.io/index.js index c5b7a94d07..826e5db452 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -199,6 +199,7 @@ Sockets.getSocketCount = function() { if (!io) { return 0; } + return Object.keys(io.sockets.sockets).length; }; @@ -206,22 +207,24 @@ Sockets.getUserSocketCount = function(uid) { if (!io) { return 0; } - return io.sockets.adapter.rooms['uid_' + uid] ? Object.keys(io.sockets.adapter.rooms['uid_' + uid]).length : 0; + var room = io.sockets.adapter.rooms['uid_' + uid]; + return room ? room.length : 0; }; Sockets.getOnlineUserCount = function() { if (!io) { return 0; } - - return io.sockets.adapter.rooms.online_users ? Object.keys(io.sockets.adapter.rooms.online_users).length : 0; + var room = io.sockets.adapter.rooms.online_users; + return room ? room.length : 0; }; Sockets.getOnlineAnonCount = function () { if (!io) { return 0; } - return io.sockets.adapter.rooms.online_guests ? Object.keys(io.sockets.adapter.rooms.online_guests).length : 0; + var room = io.sockets.adapter.rooms.online_guests; + return room ? room.length : 0; }; Sockets.reqFromSocket = function(socket) {