summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWu Cheng-Han2015-09-24 11:38:55 +0800
committerWu Cheng-Han2015-09-24 11:38:55 +0800
commit43a175e7100589cba393c335b5289b151982350f (patch)
treeb8ba204177bb60c3a2b3acb4e83d7288d03a2a70 /lib
parent950d978fe81eace56453894a02526ce252a09d33 (diff)
Added cleaner in realtime.js, to clean up users which aren't in any rooms in a interval
Diffstat (limited to 'lib')
-rw-r--r--lib/realtime.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/realtime.js b/lib/realtime.js
index b5a3b182..1e1f0107 100644
--- a/lib/realtime.js
+++ b/lib/realtime.js
@@ -80,6 +80,7 @@ function emitCheck(note) {
//actions
var users = {};
var notes = {};
+//update when the note is dirty
var updater = setInterval(function () {
async.each(Object.keys(notes), function (key, callback) {
var note = notes[key];
@@ -102,6 +103,21 @@ var updater = setInterval(function () {
if (err) return logger.error('updater error', err);
});
}, 1000);
+//clean when user not in any rooms
+var cleaner = setInterval(function () {
+ async.each(Object.keys(users), function (key, callback) {
+ var socket = realtime.io.sockets.connected[key];
+ if (!socket || !socket.rooms || socket.rooms.length <= 0) {
+ if (config.debug)
+ logger.info("cleaner found redundant user: " + key);
+ disconnectSocketQueue.push(socket);
+ disconnect(socket);
+ }
+ callback();
+ }, function (err) {
+ if (err) return logger.error('cleaner error', err);
+ });
+}, 60000);
function getStatus(callback) {
db.countFromDB(function (err, data) {