From ee963e0c2aebbdabd80134e6715bdd04cc70abe6 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 11 Jan 2014 14:03:50 -0500 Subject: [PATCH] moved reconnected socket call to SocketsMeta --- public/src/app.js | 2 +- src/socket.io/index.js | 15 --------------- src/socket.io/meta.js | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 635e888539..bfe1a4d81c 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -77,7 +77,7 @@ var socket, } app.enterRoom(room, true); - socket.emit('reconnected'); + socket.emit('api:meta.reconnected'); setTimeout(function() { reconnectEl.removeClass('active').addClass("hide"); diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 31be1962d4..f9c5e6d6b3 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -119,21 +119,6 @@ Sockets.init = function() { } }); - socket.on('reconnected', function() { - if (uid) { - topics.pushUnreadCount(uid); - user.pushNotifCount(uid); - } - - if (process.env.NODE_ENV === 'development') { - if (uid) { - winston.info('[socket] uid ' + uid + ' (' + sessionID + ') has successfully reconnected.'); - } else { - winston.info('[socket] An anonymous user (' + sessionID + ') has successfully reconnected.'); - } - } - }); - socket.on('*', function(payload, callback) { // Ignore all non-api messages if (payload.name.substr(0, 4) !== 'api:') { diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index 732dc072ff..ee48554579 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -1,13 +1,33 @@ var meta = require('../meta'), user = require('../user'), + topics = require('../topics'), logger = require('../logger'), plugins = require('../plugins'), nconf = require('nconf'), gravatar = require('gravatar'), + winston = require('winston'), SocketMeta = {}; +SocketMeta.reconnected = function(sessionData) { + var uid = sessionData.uid, + sessionID = sessionData.socket.id; + + if (uid) { + topics.pushUnreadCount(uid); + user.pushNotifCount(uid); + } + + if (process.env.NODE_ENV === 'development') { + if (uid) { + winston.info('[socket] uid ' + uid + ' (' + sessionID + ') has successfully reconnected.'); + } else { + winston.info('[socket] An anonymous user (' + sessionID + ') has successfully reconnected.'); + } + } +}; + SocketMeta.buildTitle = function(text, callback) { meta.title.build(text, function(err, title) { callback(title);