|
|
|
@ -98,8 +98,6 @@ Sockets.init = function(server) {
|
|
|
|
|
|
|
|
|
|
Sockets.server = io;
|
|
|
|
|
|
|
|
|
|
db.delete('users:online');
|
|
|
|
|
|
|
|
|
|
fs.readdir(__dirname, function(err, files) {
|
|
|
|
|
files.splice(files.indexOf('index.js'), 1);
|
|
|
|
|
|
|
|
|
@ -140,7 +138,7 @@ Sockets.init = function(server) {
|
|
|
|
|
if (uid) {
|
|
|
|
|
socket.join('uid_' + uid);
|
|
|
|
|
socket.join('online_users');
|
|
|
|
|
db.sortedSetAdd('users:online', Date.now(), uid, function(err) {
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
user: function(next) {
|
|
|
|
|
user.getUserFields(uid, ['username', 'userslug', 'picture', 'status'], next);
|
|
|
|
@ -163,7 +161,7 @@ Sockets.init = function(server) {
|
|
|
|
|
|
|
|
|
|
socket.broadcast.emit('event:user_status_change', {uid:uid, status: userData.user.status});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
socket.join('online_guests');
|
|
|
|
|
socket.emit('event:connect', {
|
|
|
|
@ -179,12 +177,7 @@ Sockets.init = function(server) {
|
|
|
|
|
socket.on('disconnect', function() {
|
|
|
|
|
var socketCount = Sockets.getUserSocketCount(uid);
|
|
|
|
|
if (uid && socketCount <= 1) {
|
|
|
|
|
db.sortedSetRemove('users:online', uid, function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return winston.error(err.message);
|
|
|
|
|
}
|
|
|
|
|
socket.broadcast.emit('event:user_status_change', {uid: uid, status: 'offline'});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onUserDisconnect(uid, socket.id, socketCount);
|
|
|
|
|