diff --git a/public/src/app.js b/public/src/app.js index 5828ac56e4..1cce50aa93 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -52,7 +52,10 @@ var socket, app.enterRoom(room, true); - socket.emit('meta.reconnected', {}, function(err, cacheBuster) { + socket.emit('meta.reconnected'); + + socket.removeAllListeners('event:nodebb.ready'); + socket.on('event:nodebb.ready', function(cacheBuster) { if (app.cacheBuster !== cacheBuster) { app.cacheBuster = cacheBuster; diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index e157a3876e..005f32fdfc 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -1,3 +1,5 @@ +'use strict'; + var meta = require('../meta'), user = require('../user'), topics = require('../topics'), @@ -8,7 +10,7 @@ var meta = require('../meta'), nconf = require('nconf'), gravatar = require('gravatar'), winston = require('winston'), - server = require('./'), + websockets = require('./'), SocketMeta = { rooms: {} @@ -23,12 +25,6 @@ SocketMeta.reconnected = function(socket, data, callback) { user.notifications.pushCount(uid); } - if (typeof callback === 'function') { - emitter.on('nodebb:ready', function() { - callback(null, meta.config['cache-buster']); - }); - } - if (process.env.NODE_ENV === 'development') { if (uid) { winston.info('[socket] uid ' + uid + ' (' + sessionID + ') has successfully reconnected.'); @@ -38,6 +34,10 @@ SocketMeta.reconnected = function(socket, data, callback) { } }; +emitter.on('nodebb:ready', function() { + websockets.server.sockets.emit('event:nodebb.ready', meta.config['cache-buster']); +}); + SocketMeta.buildTitle = function(socket, text, callback) { if (socket.uid) { user.getSettings(socket.uid, function(err, settings) { @@ -57,7 +57,7 @@ SocketMeta.getUsageStats = function(socket, data, callback) { /* Rooms */ -SocketMeta.rooms.enter = function(socket, data) { +SocketMeta.rooms.enter = function(socket, data, callback) { if(!data) { return callback(new Error('[[error:invalid-data]]')); } @@ -74,13 +74,13 @@ SocketMeta.rooms.enter = function(socket, data) { module.parent.exports.updateRoomBrowsingText(data.enter); - if (data.enter != 'admin') { - server.in('admin').emit('event:meta.rooms.update', null, server.server.sockets.manager.rooms); + if (data.enter !== 'admin') { + websockets.in('admin').emit('event:meta.rooms.update', null, websockets.server.sockets.manager.rooms); } }; SocketMeta.rooms.getAll = function(socket, data, callback) { - callback(null, server.server.sockets.manager.rooms); + callback(null, websockets.server.sockets.manager.rooms); }; /* Exports */