|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var os = require('os');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var winston = require('winston');
|
|
|
|
@ -99,10 +100,11 @@ SocketRooms.getAll = function (socket, data, callback) {
|
|
|
|
|
return topic.tid;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topics.getTopicsFields(topTenTids, ['title'], function (err, titles) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
topics.getTopicsFields(topTenTids, ['title'], next);
|
|
|
|
|
},
|
|
|
|
|
function (titles, next) {
|
|
|
|
|
totals.topics = {};
|
|
|
|
|
topTenTopics.forEach(function (topic, index) {
|
|
|
|
|
totals.topics[topic.tid] = {
|
|
|
|
@ -110,21 +112,21 @@ SocketRooms.getAll = function (socket, data, callback) {
|
|
|
|
|
title: validator.escape(String(titles[index].title))
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(null, totals);
|
|
|
|
|
});
|
|
|
|
|
next(null, totals);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketRooms.getOnlineUserCount = function (io) {
|
|
|
|
|
if (!io) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
|
|
if (io) {
|
|
|
|
|
for (var key in io.sockets.adapter.rooms) {
|
|
|
|
|
if (io.sockets.adapter.rooms.hasOwnProperty(key) && key.startsWith('uid_')) {
|
|
|
|
|
++ count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
};
|
|
|
|
@ -132,25 +134,29 @@ SocketRooms.getOnlineUserCount = function (io) {
|
|
|
|
|
SocketRooms.getLocalStats = function (callback) {
|
|
|
|
|
var io = require('../index').server;
|
|
|
|
|
|
|
|
|
|
if (!io) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var roomClients = io.sockets.adapter.rooms;
|
|
|
|
|
var socketData = {
|
|
|
|
|
onlineGuestCount: roomClients.online_guests ? roomClients.online_guests.length : 0,
|
|
|
|
|
onlineRegisteredCount: SocketRooms.getOnlineUserCount(io),
|
|
|
|
|
socketCount: Object.keys(io.sockets.sockets).length,
|
|
|
|
|
onlineGuestCount: 0,
|
|
|
|
|
onlineRegisteredCount: 0,
|
|
|
|
|
socketCount: 0,
|
|
|
|
|
users: {
|
|
|
|
|
categories: roomClients.categories ? roomClients.categories.length : 0,
|
|
|
|
|
recent: roomClients.recent_topics ? roomClients.recent_topics.length : 0,
|
|
|
|
|
unread: roomClients.unread_topics ? roomClients.unread_topics.length : 0,
|
|
|
|
|
categories: 0,
|
|
|
|
|
recent: 0,
|
|
|
|
|
unread: 0,
|
|
|
|
|
topics: 0,
|
|
|
|
|
category: 0
|
|
|
|
|
},
|
|
|
|
|
topics: {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (io) {
|
|
|
|
|
var roomClients = io.sockets.adapter.rooms;
|
|
|
|
|
socketData.onlineGuestCount = roomClients.online_guests ? roomClients.online_guests.length : 0;
|
|
|
|
|
socketData.onlineRegisteredCount = SocketRooms.getOnlineUserCount(io);
|
|
|
|
|
socketData.socketCount = Object.keys(io.sockets.sockets).length;
|
|
|
|
|
socketData.users.categories = roomClients.categories ? roomClients.categories.length : 0;
|
|
|
|
|
socketData.users.recent = roomClients.recent_topics ? roomClients.recent_topics.length : 0;
|
|
|
|
|
socketData.users.unread = roomClients.unread_topics ? roomClients.unread_topics.length : 0;
|
|
|
|
|
|
|
|
|
|
var topTenTopics = [];
|
|
|
|
|
var tid;
|
|
|
|
|
|
|
|
|
@ -171,6 +177,8 @@ SocketRooms.getLocalStats = function (callback) {
|
|
|
|
|
}).slice(0, 10);
|
|
|
|
|
|
|
|
|
|
socketData.topics = topTenTopics;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(null, socketData);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|