Skip to content

Commit

Permalink
Fix multi-bugs based on room sockets list. The code is temporary and …
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrugne committed Jul 3, 2014
1 parent be31f37 commit 822d2c8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions server/ws/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ module.exports = {
* @returns {Array}
*/
userSockets: function(io, userId) {
return this.roomSockets(io, 'user:'+userId).sockets;
return this.roomSockets(io, 'user:'+userId);
},

/**
Expand Down Expand Up @@ -295,7 +295,7 @@ module.exports = {
roomUsers: function(io, name) {
var list = [];
var already = [];
var sockets = io.sockets.in(name).sockets;
var sockets = this.roomSockets(io, name);
for (var i=0; i < sockets.length; i++) {
var u = sockets[i];
if (!_.contains(already, u.getUserId())) {
Expand All @@ -316,7 +316,17 @@ module.exports = {
* @returns {Array}
*/
roomSockets: function(io, name) {
return io.sockets.in(name);
// return io.sockets.in(name);
// source: http://stackoverflow.com/questions/23858604/how-to-get-rooms-clients-list-in-socket-io-1-0
// until a cleaner method is implemented in socket.io
var res = [];
var room = io.sockets.adapter.rooms[name];
if (room) {
for (var id in room) {
res.push(io.sockets.adapter.nsp.connected[id]);
}
}
return res;
},

/**
Expand Down

0 comments on commit 822d2c8

Please sign in to comment.