Skip to content

Commit

Permalink
socket: rename joined to rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Dec 24, 2012
1 parent c54011b commit 0881dfb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Socket(nsp, client){
this.id = client.id;
this.request = client.request;
this.client = client;
this.joined = [];
this.rooms = [];
this.acks = {};
this.connected = true;
this.disconnected = false;
Expand Down Expand Up @@ -100,7 +100,7 @@ Socket.prototype.emit = function(ev){

// access last argument to see if it's an ACK callback
if ('function' == typeof args[args.length - 1]) {
if (this.rooms || (this.flags && this.flags.broadcast)) {
if (this._rooms || (this.flags && this.flags.broadcast)) {
throw new Error('Callbacks are not supported when broadcasting');
}

Expand All @@ -109,10 +109,10 @@ Socket.prototype.emit = function(ev){
packet.id = this.nsp.ids++;
}

if (this.rooms || (this.flags && this.flags.broadcast)) {
if (this._rooms || (this.flags && this.flags.broadcast)) {
this.adapter.broadcast(packet, {
except: [this.id],
rooms: this.rooms,
rooms: this._rooms,
flags: this.flags
});
} else {
Expand All @@ -121,7 +121,7 @@ Socket.prototype.emit = function(ev){
}

// reset flags
delete this.rooms;
delete this._rooms;
delete this.flags;
}
return this;
Expand All @@ -137,8 +137,8 @@ Socket.prototype.emit = function(ev){

Socket.prototype.to =
Socket.prototype.in = function(name){
this.rooms = this.rooms || [];
if (!~this.rooms.indexOf(name)) this.rooms.push(name);
this._rooms = this._rooms || [];
if (!~this._rooms.indexOf(name)) this._rooms.push(name);
return this;
};

Expand Down Expand Up @@ -181,11 +181,11 @@ Socket.prototype.packet = function(packet){
Socket.prototype.join = function(room, fn){
debug('joining room %s', room);
var self = this;
if (~this.joined.indexOf(room)) return this;
if (~this.rooms.indexOf(room)) return this;
this.adapter.add(this.id, room, function(err){
if (err) return fn && fn(err);
debug('joined room %s', room);
self.joined.push(room);
self.rooms.push(room);
fn && fn(null);
});
return this;
Expand All @@ -206,7 +206,7 @@ Socket.prototype.leave = function(room, fn){
this.adapter.del(this.id, room, function(err){
if (err) return fn && fn(err);
debug('left room %s', room);
self.joined.splice(self.joined.indexOf(room, 1));
self.rooms.splice(self.rooms.indexOf(room, 1));
fn && fn(null);
});
return this;
Expand Down

0 comments on commit 0881dfb

Please sign in to comment.