Skip to content

Commit

Permalink
jslint
Browse files Browse the repository at this point in the history
  • Loading branch information
ali asaria committed Oct 12, 2014
1 parent 6500143 commit 16333ae
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions lib/rooms.js
Expand Up @@ -34,7 +34,7 @@ exports.add_to_room = function (client, room, callback) {
room_users[room].add(client.username);

callback(rooms[room].array());
}
};

// Remove a client from all rooms and return the username:client
// mapping for everybody in those rooms.
Expand Down Expand Up @@ -64,7 +64,7 @@ exports.remove_from_all_rooms = function (client, callback) {
//console.log('Client ' + client.username + ' (' + client.id + ') disconnected.');
delete sid_rooms[client.id];
callback(affected_clients.array());
}
};

// Remove a client from a room and return the username:client mapping
// for everybody in that room. Returns [] if the room does not exist,
Expand All @@ -74,7 +74,7 @@ function remove_from_room(client, room, callback) {
callback([]);
return;
}

// Delete from the room
rooms[room].remove(client);
if (rooms[room].size() === 0)
Expand Down Expand Up @@ -109,7 +109,7 @@ exports.room_clients_other_than_me = function(room, client) {
{
var clients = rooms[room];
//console.dir(clients.array());

clients.remove(client);
//console.dir(clients.array());
return clients.array();
Expand All @@ -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)
exports.get_room = function (client) {
exports.get_room = function (client) {
var client_rooms = null;

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];
else
return null
}
return null;
};


// Generic server code
Expand All @@ -147,11 +149,11 @@ exports.add_to_room_and_announce = function (client, room, msg) {
clients[i].json.send(msg);
}
});
}
};

/*
exports.on_leave_room = function (client, room) {
remove_from_room(client, room, function(clients) {
console.log(client + ' disconnected, yo');
console.log(clients);
Expand All @@ -162,7 +164,7 @@ exports.on_leave_room = function (client, room) {
action: 'disconnected'
});
});
}*/

//remember that this announces to all rooms that this client was a member of
Expand All @@ -174,7 +176,7 @@ exports.remove_from_all_rooms_and_announce = function (client, msg) {
clients[i].json.send(msg);
}
});
}
};

//////////////////////////////
// Broadcasting functions
Expand All @@ -198,7 +200,7 @@ exports.broadcast_room = function(room, msg) {
// Broadcast message to all the other clients that are in rooms with this client
exports.broadcast_to_roommates = function (client, msg) {
var roommates = new sets.Set();

if (sid_rooms.hasOwnProperty(client.id))
{
var client_rooms = sid_rooms[client.id].array();
Expand All @@ -213,17 +215,17 @@ exports.broadcast_to_roommates = function (client, msg) {
}
}
}

//remove self from the set
roommates.remove(client);
roommates = roommates.array();

//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);
roommates[i].json.send(msg);
roommates[k].json.send(msg);
}
}
};

0 comments on commit 16333ae

Please sign in to comment.