From 0a2d54318641bcc8ddea73d02892c3c6c9d980b3 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 28 Nov 2014 21:35:34 -0500 Subject: [PATCH] removed getUserSockets --- src/routes/authentication.js | 4 ++-- src/socket.io/index.js | 28 +--------------------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 1c938e185c..9810d0a45d 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -246,10 +246,10 @@ } function logout(req, res) { - if (req.user && parseInt(req.user.uid, 10) > 0) { + if (req.user && parseInt(req.user.uid, 10) > 0 && req.sessionID) { require('../socket.io').logoutUser(req.user.uid); - + db.sessionStore.destroy(req.sessionID); req.logout(); } diff --git a/src/socket.io/index.js b/src/socket.io/index.js index a5d2e7945d..24210fd194 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -216,14 +216,7 @@ function callMethod(method, socket, params, callback) { } Sockets.logoutUser = function(uid) { - Sockets.getUserSockets(uid).forEach(function(socket) { - if (socket.handshake && socket.handshake.signedCookies && socket.handshake.signedCookies['express.sid']) { - db.sessionStore.destroy(socket.handshake.signedCookies['express.sid']); - } - - socket.emit('event:disconnect'); - socket.disconnect(); - }); + io.sockets.in('uid_' + uid).emit('event:disconnect'); }; Sockets.in = function(room) { @@ -254,25 +247,6 @@ Sockets.getOnlineAnonCount = function () { return Array.isArray(guestSocketIds) ? guestSocketIds.length : 0; }; -Sockets.getUserSockets = function(uid) { - // TODO: doesn't work in cluster - - var userSocketIds = Object.keys(io.sockets.adapter.rooms['uid_' + uid] || {}); - if (!Array.isArray(userSocketIds) || !userSocketIds.length) { - return []; - } - uid = parseInt(uid, 10); - - var sockets = []; - userSocketIds.forEach(function(sid) { - if (io.sockets.connected[sid] && io.sockets.connected[sid].uid === uid) { - sockets.push(io.sockets.connected[sid]) ; - } - }); - - return sockets; -}; - Sockets.reqFromSocket = function(socket) { var headers = socket.request.headers, host = headers.host,