mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 15:06:38 +02:00
better error checking with socket broadcast method
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user