This commit is contained in:
ali asaria 2014-10-12 13:40:13 -04:00
parent 6500143cdc
commit 16333ae521

View file

@ -34,7 +34,7 @@ exports.add_to_room = function (client, room, callback) {
room_users[room].add(client.username); room_users[room].add(client.username);
callback(rooms[room].array()); callback(rooms[room].array());
} };
// Remove a client from all rooms and return the username:client // Remove a client from all rooms and return the username:client
// mapping for everybody in those rooms. // mapping for everybody in those rooms.
@ -64,7 +64,7 @@ exports.remove_from_all_rooms = function (client, callback) {
//console.log('Client ' + client.username + ' (' + client.id + ') disconnected.'); //console.log('Client ' + client.username + ' (' + client.id + ') disconnected.');
delete sid_rooms[client.id]; delete sid_rooms[client.id];
callback(affected_clients.array()); callback(affected_clients.array());
} };
// Remove a client from a room and return the username:client mapping // Remove a client from a room and return the username:client mapping
// for everybody in that room. Returns [] if the room does not exist, // for everybody in that room. Returns [] if the room does not exist,
@ -74,7 +74,7 @@ function remove_from_room(client, room, callback) {
callback([]); callback([]);
return; return;
} }
// Delete from the room // Delete from the room
rooms[room].remove(client); rooms[room].remove(client);
if (rooms[room].size() === 0) if (rooms[room].size() === 0)
@ -109,7 +109,7 @@ exports.room_clients_other_than_me = function(room, client) {
{ {
var clients = rooms[room]; var clients = rooms[room];
//console.dir(clients.array()); //console.dir(clients.array());
clients.remove(client); clients.remove(client);
//console.dir(clients.array()); //console.dir(clients.array());
return clients.array(); return clients.array();
@ -121,17 +121,19 @@ exports.room_clients_other_than_me = function(room, client) {
}; };
//gets the current room of the client (assumes one room -- will select first one if in multiple) //gets the current room of the client (assumes one room -- will select first one if in multiple)
exports.get_room = function (client) { exports.get_room = function (client) {
var client_rooms = null;
if (sid_rooms.hasOwnProperty(client.id)) if (sid_rooms.hasOwnProperty(client.id))
{ {
var client_rooms = sid_rooms[client.id].array(); client_rooms = sid_rooms[client.id].array();
} }
if ( typeof(client_rooms) != undefined ) if ( client_rooms !== null )
return client_rooms[0]; return client_rooms[0];
else else
return null return null;
} };
// Generic server code // Generic server code
@ -147,11 +149,11 @@ exports.add_to_room_and_announce = function (client, room, msg) {
clients[i].json.send(msg); clients[i].json.send(msg);
} }
}); });
} };
/* /*
exports.on_leave_room = function (client, room) { exports.on_leave_room = function (client, room) {
remove_from_room(client, room, function(clients) { remove_from_room(client, room, function(clients) {
console.log(client + ' disconnected, yo'); console.log(client + ' disconnected, yo');
console.log(clients); console.log(clients);
@ -162,7 +164,7 @@ exports.on_leave_room = function (client, room) {
action: 'disconnected' action: 'disconnected'
}); });
}); });
}*/ }*/
//remember that this announces to all rooms that this client was a member of //remember that this announces to all rooms that this client was a member of
@ -174,7 +176,7 @@ exports.remove_from_all_rooms_and_announce = function (client, msg) {
clients[i].json.send(msg); clients[i].json.send(msg);
} }
}); });
} };
////////////////////////////// //////////////////////////////
// Broadcasting functions // Broadcasting functions
@ -198,7 +200,7 @@ exports.broadcast_room = function(room, msg) {
// Broadcast message to all the other clients that are in rooms with this client // Broadcast message to all the other clients that are in rooms with this client
exports.broadcast_to_roommates = function (client, msg) { exports.broadcast_to_roommates = function (client, msg) {
var roommates = new sets.Set(); var roommates = new sets.Set();
if (sid_rooms.hasOwnProperty(client.id)) if (sid_rooms.hasOwnProperty(client.id))
{ {
var client_rooms = sid_rooms[client.id].array(); var client_rooms = sid_rooms[client.id].array();
@ -213,17 +215,17 @@ exports.broadcast_to_roommates = function (client, msg) {
} }
} }
} }
//remove self from the set //remove self from the set
roommates.remove(client); roommates.remove(client);
roommates = roommates.array(); roommates = roommates.array();
//console.log('client: ' + client.id + " is broadcasting to: "); //console.log('client: ' + client.id + " is broadcasting to: ");
for (var i = 0; i < roommates.length; i++) for (var k = 0; k < roommates.length; k++)
{ {
//console.log(' - ' + roommates[i].id); //console.log(' - ' + roommates[i].id);
roommates[i].json.send(msg); roommates[k].json.send(msg);
} }
} };