fixed active users socket calls in ACP

v1.18.x
Julian Lam 11 years ago
parent 3fb44d7693
commit aa689a7a29

@ -2,25 +2,11 @@ define(function() {
var Admin = {};
Admin.init = function() {
ajaxify.register_events(['api:get_all_rooms']);
ajaxify.register_events(['api:meta.rooms.getAll']);
app.enterRoom('admin');
socket.emit('api:meta.rooms.getAll', function(data) {
var active_users = document.getElementById('active_users'),
total = 0;
active_users.innerHTML = '';
for (var room in data) {
if (room !== '') {
var count = data[room].length;
total += count;
active_users.innerHTML = active_users.innerHTML + "<div class='alert alert-success'><strong>" + room + "</strong> " + count + " active user" + (count > 1 ? "s" : "") + "</div>";
}
}
document.getElementById('connections').innerHTML = total;
});
socket.emit('api:meta.rooms.getAll', Admin.updateRoomUsage);
socket.on('event:meta.rooms.update', Admin.updateRoomUsage);
$('#logout-link').on('click', function() {
$.post(RELATIVE_PATH + '/logout', {
@ -31,5 +17,22 @@ define(function() {
})
};
Admin.updateRoomUsage = function(data) {
console.log('room usage updating', data);
var active_users = document.getElementById('active_users'),
total = 0;
active_users.innerHTML = '';
for (var room in data) {
if (room !== '') {
var count = data[room].length;
total += count;
active_users.innerHTML = active_users.innerHTML + "<div class='alert alert-success'><strong>" + room + "</strong> " + count + " active user" + (count > 1 ? "s" : "") + "</div>";
}
}
document.getElementById('connections').innerHTML = total;
};
return Admin;
});

@ -10,9 +10,21 @@ var groups = require('../groups'),
},
async = require('async'),
winston = require('winston'),
SocketAdmin = {};
SocketAdmin.before = function(sessionData, next) {
// Verify administrative privileges
user.isAdministrator(sessionData.uid, function(err, isAdmin) {
if (isAdmin) {
next();
} else {
winston.warn('[socket.io] Call to admin method blocked (accessed by uid ' + sessionData.uid + ')');
}
});
};
/* Topics */
SocketAdmin.topics = {};

@ -130,6 +130,7 @@ Sockets.init = function() {
} else {
// Deconstruct the message
var parts = payload.name.slice(4).split('.'),
namespace = parts.slice(0, 1),
methodToCall = parts.reduce(function(prev, cur) {
if (prev !== null && prev[cur]) {
return prev[cur];
@ -157,8 +158,15 @@ Sockets.init = function() {
}
socketArgs.push(sessionData);
// Call the requested method
if (Namespaces[namespace].before) {
Namespaces[namespace].before(sessionData, function() {
methodToCall.apply(Namespaces, socketArgs);
});
} else {
methodToCall.apply(Namespaces, socketArgs);
}
// winston.info('[socket.io] Executing: ' + payload.name);
methodToCall.apply(Namespaces, socketArgs);
} else {
winston.warn('[socket.io] Unrecognized message: ' + payload.name);
}

@ -88,7 +88,7 @@ SocketMeta.rooms.enter = function(data, sessionData) {
module.parent.exports.updateRoomBrowsingText(data.enter);
if (data.enter != 'admin') {
sessionData.server.sockets.in('admin').emit('api:get_all_rooms', sessionData.server.sockets.manager.rooms);
sessionData.server.sockets.in('admin').emit('event:meta.rooms.update', sessionData.server.sockets.manager.rooms);
}
};

Loading…
Cancel
Save