Commit 0a3b02cf authored by Will Langstroth's avatar Will Langstroth
Browse files

sessionId to id in lib/rooms.js

parent d03cc8ba
......@@ -22,10 +22,10 @@ var sid_rooms = {};
// Add a client to a room and return the sid:client mapping.
exports.add_to_room = function (client, room, callback) {
//console.log('Client ' + client.username + ' (' + client.sessionId + ') added to room ' + room);
//console.log('Client ' + client.username + ' (' + client.id + ') added to room ' + room);
if (!(sid_rooms.hasOwnProperty(client.sessionId))) sid_rooms[client.sessionId] = new sets.Set();
sid_rooms[client.sessionId].add(room);
if (!(sid_rooms.hasOwnProperty(client.id))) sid_rooms[client.id] = new sets.Set();
sid_rooms[client.id].add(room);
if (!(rooms.hasOwnProperty(room))) rooms[room] = new sets.Set();
rooms[room].add(client);
......@@ -40,8 +40,8 @@ exports.add_to_room = function (client, room, callback) {
// mapping for everybody in those rooms.
exports.remove_from_all_rooms = function (client, callback) {
var affected_clients = new sets.Set();
if (sid_rooms.hasOwnProperty(client.sessionId)) {
var client_rooms = sid_rooms[client.sessionId].array();
if (sid_rooms.hasOwnProperty(client.id)) {
var client_rooms = sid_rooms[client.id].array();
for (var i = 0; i < client_rooms.length; i++) {
var room = client_rooms[i];
if (rooms.hasOwnProperty(room)) {
......@@ -61,8 +61,8 @@ exports.remove_from_all_rooms = function (client, callback) {
}
}
}
console.log('Client ' + client.username + ' (' + client.sessionId + ') disconnected.');
delete sid_rooms[client.sessionId];
console.log('Client ' + client.username + ' (' + client.id + ') disconnected.');
delete sid_rooms[client.id];
callback(affected_clients.array());
}
......@@ -122,9 +122,9 @@ 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) {
if (sid_rooms.hasOwnProperty(client.sessionId))
if (sid_rooms.hasOwnProperty(client.id))
{
var client_rooms = sid_rooms[client.sessionId].array();
var client_rooms = sid_rooms[client.id].array();
}
if ( typeof(client_rooms) != undefined )
......@@ -143,7 +143,7 @@ exports.add_to_room_and_announce = function (client, room, msg) {
// Broadcast new-user notification
for (var i = 0; i < clients.length; i++)
{
if (clients[i].sessionId != client.sessionId)
if (clients[i].id != client.id)
clients[i].send(msg);
}
});
......@@ -170,7 +170,7 @@ exports.remove_from_all_rooms_and_announce = function (client, msg) {
exports.remove_from_all_rooms(client, function(clients) {
for (var i = 0; i < clients.length; i++)
{
if (clients[i].sessionId != client.sessionId)
if (clients[i].id != client.id)
clients[i].send(msg);
}
});
......@@ -199,9 +199,9 @@ exports.broadcast_room = function(room, msg) {
exports.broadcast_to_roommates = function (client, msg) {
var roommates = new sets.Set();
if (sid_rooms.hasOwnProperty(client.sessionId))
if (sid_rooms.hasOwnProperty(client.id))
{
var client_rooms = sid_rooms[client.sessionId].array();
var client_rooms = sid_rooms[client.id].array();
for (var i = 0; i < client_rooms.length; i++)
{
var room = client_rooms[i];
......@@ -218,12 +218,12 @@ exports.broadcast_to_roommates = function (client, msg) {
roommates.remove(client);
roommates = roommates.array();
console.log('client: ' + client.sessionId + " is broadcasting to: ");
console.log('client: ' + client.id + " is broadcasting to: ");
for (var i = 0; i < roommates.length; i++)
{
console.log(' - ' + roommates[i].sessionId);
console.log(' - ' + roommates[i].id);
roommates[i].send(msg);
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment