v1.18.x
Baris Soner Usakli 11 years ago
parent fb8fbb2372
commit d54e2fba9e

@ -18,6 +18,7 @@ define(function() {
};
Admin.updateRoomUsage = function(err, data) {
function getUserCountIn(room) {
var count = 0;
for(var user in data[room]) {
@ -25,27 +26,36 @@ define(function() {
}
return count;
}
var active_users = $('#active_users'),
var active_users = $('#active_users').html(''),
total = 0;
if(!active_users.length) {
return;
}
active_users.html('');
var usersHtml = '';
var sortedData = [];
for (var room in data) {
if (room !== '') {
var count = getUserCountIn(room);
total += count;
usersHtml += "<div class='alert alert-success'><strong>" + room + "</strong> " + count + " active user" + (count > 1 ? "s" : "") + "</div>";
sortedData.push({room: room, count: data[room].length});
total += data[room].length;
}
}
sortedData.sort(function(a, b) {
return parseInt(b.count, 10) - parseInt(a.count, 10);
});
var usersHtml = '';
for(var i=0; i<sortedData.length; ++i) {
usersHtml += "<div class='alert alert-success'><strong>" + sortedData[i].room + "</strong> " +
sortedData[i].count + " active user" + (sortedData[i].count > 1 ? "s" : "") + "</div>";
}
active_users.html(usersHtml);
document.getElementById('connections').innerHTML = total;
$('#connections').html(total);
};
return Admin;

@ -75,12 +75,12 @@ var DebugRoute = function(app) {
app.get('/test', function(req, res) {
/*topics.getTopicPosts2(2, 0, 10, 5, function(err, data) {
res.json(data);
})*/
topics.getTopicWithPosts(2, 1, 0, -1, true, function (err, topicData) {
res.json(topicData);
var db = require('./../database');
db.getSortedSetRevRange('topics:recent', 0 , -1, function(err, tids) {
res.json(tids);
});
});
});

@ -22,12 +22,11 @@ var SocketIO = require('socket.io'),
/* === */
var users = {},
io;
var io;
Sockets.userSockets = {};
Sockets.rooms = {};
Sockets.init = function(server) {
@ -59,9 +58,9 @@ Sockets.init = function(server) {
sessionID = socket.handshake.signedCookies["express.sid"];
db.sessionStore.get(sessionID, function(err, sessionData) {
if (!err && sessionData && sessionData.passport && sessionData.passport.user) {
uid = users[sessionID] = sessionData.passport.user;
uid = sessionData.passport.user;
} else {
uid = users[sessionID] = 0;
uid = 0;
}
socket.uid = parseInt(uid, 10);
@ -110,8 +109,8 @@ Sockets.init = function(server) {
}
if (Sockets.userSockets[uid] && Sockets.userSockets[uid].length === 0) {
delete users[sessionID];
delete Sockets.userSockets[uid];
if (uid) {
db.sortedSetRemove('users:online', uid, function(err, data) {
});
@ -126,17 +125,10 @@ Sockets.init = function(server) {
emitOnlineUserCount();
for (var roomName in Sockets.rooms) {
if (Sockets.rooms.hasOwnProperty(roomName)) {
socket.leave(roomName);
if (Sockets.rooms[roomName][socket.id]) {
delete Sockets.rooms[roomName][socket.id];
}
updateRoomBrowsingText(roomName);
}
for(var roomName in io.sockets.manager.roomClients[socket.id]) {
updateRoomBrowsingText(roomName.slice(1));
}
});
socket.on('*', function(payload, callback) {
@ -222,9 +214,10 @@ function updateRoomBrowsingText(roomName) {
function getUidsInRoom(room) {
var uids = [];
for (var socketId in room) {
if (uids.indexOf(room[socketId]) === -1) {
uids.push(room[socketId]);
var clients = io.sockets.clients(roomName);
for(var i=0; i<clients.length; ++i) {
if (uids.indexOf(clients[i].uid) === -1 && clients[i].uid !== 0) {
uids.push(clients[i].uid);
}
}
return uids;
@ -235,15 +228,14 @@ function updateRoomBrowsingText(roomName) {
var anonCount = 0;
for (var i = 0; i < clients.length; ++i) {
var hs = clients[i].handshake;
if (hs && clients[i].state && clients[i].state.user.uid === 0) {
if(clients[i].uid === 0) {
++anonCount;
}
}
return anonCount;
}
var uids = getUidsInRoom(Sockets.rooms[roomName]),
var uids = getUidsInRoom(roomName),
anonymousCount = getAnonymousCount(roomName);
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], function(err, users) {

@ -84,18 +84,6 @@ SocketMeta.rooms.enter = function(socket, data) {
}
socket.join(data.enter);
server.rooms[data.enter] = server.rooms[data.enter] || {};
if (socket.uid) {
server.rooms[data.enter][socket.id] = socket.uid;
if (data.leave && server.rooms[data.leave] && server.rooms[data.leave][socket.id] && data.enter !== data.leave) {
delete server.rooms[data.leave][socket.id];
if(!Object.keys(server.rooms[data.leave]).length) {
delete server.rooms[data.leave];
}
}
}
if (data.leave) {
module.parent.exports.updateRoomBrowsingText(data.leave);
@ -104,12 +92,12 @@ SocketMeta.rooms.enter = function(socket, data) {
module.parent.exports.updateRoomBrowsingText(data.enter);
if (data.enter != 'admin') {
server.in('admin').emit('event:meta.rooms.update', null, server.rooms);
server.in('admin').emit('event:meta.rooms.update', null, server.server.sockets.manager.rooms);
}
};
SocketMeta.rooms.getAll = function(socket, data, callback) {
callback(null, server.rooms);
callback(null, server.server.sockets.manager.rooms);
};
/* Exports */

Loading…
Cancel
Save