diff --git a/src/user.js b/src/user.js index 8ec58e6f44..843a099f09 100644 --- a/src/user.js +++ b/src/user.js @@ -924,7 +924,6 @@ var utils = require('./../public/src/utils.js'), }); }; - User.active = { get_record : function(socket) { RDB.mget(['global:active_user_record', 'global:active_user_record_date'], function(err, data) { diff --git a/src/websockets.js b/src/websockets.js index 9a703ebb0c..06baff010a 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -82,6 +82,18 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), if(index !== -1) { userSockets[uid].splice(index, 1); } + + for(var roomName in rooms) { + + socket.leave(roomName); + + if(rooms[roomName][hs.sessionID]) { + delete rooms[roomName][hs.sessionID]; + } + + updateRoomBrowsingText(roomName); + } + // } }); @@ -89,20 +101,33 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), socket.emit('api:get_all_rooms', io.sockets.manager.rooms); }) - socket.on('event:enter_room', function(data) { - if (data.leave !== null) socket.leave (data.leave); - socket.join(data.enter); + function updateRoomBrowsingText(roomName) { - rooms[data.enter] = rooms[data.enter] || {}; - if (uid) { - rooms[data.enter][uid] = true; - if (rooms[data.leave]) { - delete rooms[data.leave][uid]; + function getUidsInRoom(room) { + var uids = []; + for(var sessionId in room) { + if(uids.indexOf(room[sessionId]) === -1) + uids.push(room[sessionId]); } + return uids; } - var uids = Object.keys(rooms[data.enter] || {}); - var anonymousCount = io.sockets.clients(data.enter).length - uids.length; + function getAnonymousCount(roomName) { + var clients = io.sockets.clients(roomName); + var anonCount = 0; + + for(var i=0; i