updating web sockets so that all connections are stored in a userSockets array

v1.18.x
Julian Lam 12 years ago
parent cf64952918
commit 35dae6c0ec

@ -51,9 +51,10 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
io.sockets.on('connection', function(socket) {
var hs = socket.handshake;
var uid = users[hs.sessionID];
userSockets[uid] = socket;
userSockets[uid] = userSockets[uid] || [];
userSockets[uid].push(socket);
user.go_online(uid);
@ -260,11 +261,14 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
var touid = data.touid;
if(userSockets[touid]) {
var msg = utils.strip_tags(data.message);
var msg = utils.strip_tags(data.message),
numSockets = userSockets[touid].length;
user.getUserField(uid, 'username', function(username) {
var finalMessage = username + ' says : ' + msg;
userSockets[touid].emit('chatMessage', {fromuid:uid, username:username, message:finalMessage});
for(var x=0;x>numSockets;x++) {
userSockets[touid][x].emit('chatMessage', {fromuid:uid, username:username, message:finalMessage});
}
});
}
});

Loading…
Cancel
Save