sessionId to id in lib/rooms.js

This commit is contained in:
Will Langstroth 2011-09-06 00:06:01 -04:00
parent d03cc8ba38
commit 0a3b02cf7d

View file

@ -22,10 +22,10 @@ var sid_rooms = {};
// Add a client to a room and return the sid:client mapping. // Add a client to a room and return the sid:client mapping.
exports.add_to_room = function (client, room, callback) { 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(); if (!(sid_rooms.hasOwnProperty(client.id))) sid_rooms[client.id] = new sets.Set();
sid_rooms[client.sessionId].add(room); sid_rooms[client.id].add(room);
if (!(rooms.hasOwnProperty(room))) rooms[room] = new sets.Set(); if (!(rooms.hasOwnProperty(room))) rooms[room] = new sets.Set();
rooms[room].add(client); rooms[room].add(client);
@ -40,8 +40,8 @@ exports.add_to_room = function (client, room, callback) {
// mapping for everybody in those rooms. // mapping for everybody in those rooms.
exports.remove_from_all_rooms = function (client, callback) { exports.remove_from_all_rooms = function (client, callback) {
var affected_clients = new sets.Set(); var affected_clients = 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++) { for (var i = 0; i < client_rooms.length; i++) {
var room = client_rooms[i]; var room = client_rooms[i];
if (rooms.hasOwnProperty(room)) { if (rooms.hasOwnProperty(room)) {
@ -61,8 +61,8 @@ exports.remove_from_all_rooms = function (client, callback) {
} }
} }
} }
console.log('Client ' + client.username + ' (' + client.sessionId + ') disconnected.'); console.log('Client ' + client.username + ' (' + client.id + ') disconnected.');
delete sid_rooms[client.sessionId]; delete sid_rooms[client.id];
callback(affected_clients.array()); 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) //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) {
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 ) if ( typeof(client_rooms) != undefined )
@ -143,7 +143,7 @@ exports.add_to_room_and_announce = function (client, room, msg) {
// Broadcast new-user notification // Broadcast new-user notification
for (var i = 0; i < clients.length; i++) for (var i = 0; i < clients.length; i++)
{ {
if (clients[i].sessionId != client.sessionId) if (clients[i].id != client.id)
clients[i].send(msg); 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) { exports.remove_from_all_rooms(client, function(clients) {
for (var i = 0; i < clients.length; i++) for (var i = 0; i < clients.length; i++)
{ {
if (clients[i].sessionId != client.sessionId) if (clients[i].id != client.id)
clients[i].send(msg); clients[i].send(msg);
} }
}); });
@ -199,9 +199,9 @@ exports.broadcast_room = function(room, msg) {
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.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++) for (var i = 0; i < client_rooms.length; i++)
{ {
var room = client_rooms[i]; var room = client_rooms[i];
@ -218,12 +218,12 @@ exports.broadcast_to_roommates = function (client, msg) {
roommates.remove(client); roommates.remove(client);
roommates = roommates.array(); 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++) for (var i = 0; i < roommates.length; i++)
{ {
console.log(' - ' + roommates[i].sessionId); console.log(' - ' + roommates[i].id);
roommates[i].send(msg); roommates[i].send(msg);
} }
} }