From 0a3b02cf7df12d3169f2e11928b3d30c20ccb966 Mon Sep 17 00:00:00 2001 From: Will Langstroth Date: Tue, 6 Sep 2011 00:06:01 -0400 Subject: [PATCH] sessionId to id in lib/rooms.js --- lib/rooms.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/rooms.js b/lib/rooms.js index d52c5c0..8f67f1b 100644 --- a/lib/rooms.js +++ b/lib/rooms.js @@ -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 +}