diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index c47999de0a..54b8fbe93f 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -142,7 +142,7 @@ define('chat', ['components', 'taskbar', 'string', 'sounds', 'forum/chats', 'tra } }); - callback(chats); + callback(null, chats); }); socket.on('event:chats.open', function(data) { diff --git a/src/socket.io/rooms.js b/src/socket.io/rooms.js index c32f9a5dc9..615d650cd6 100644 --- a/src/socket.io/rooms.js +++ b/src/socket.io/rooms.js @@ -39,19 +39,29 @@ rooms.broadcast = function(socket, room, msg, data, callback) { callback = callback || function() {}; + // Filter out socketIds that aren't actually connected + socketIds = socketIds.filter(function(id) { + return io.server.sockets.connected.hasOwnProperty(id); + }); + async.map(socketIds, function(id, next) { - var timeout; + var timeout, + timeoutPassed = false; + if (socket.id === id) { return setImmediate(next, null, []); } timeout = setTimeout(function() { + timeoutPassed = true; next(null, []); }, 500); - io.server.sockets.connected[id].emit(msg, data || {}, function(chats) { + io.server.sockets.connected[id].emit(msg, data || {}, function(err, returnData) { clearTimeout(timeout); - next(null, chats); + if (!timeoutPassed) { + next(null, returnData); + } }); }, callback); };