Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created July 23, 2011 18:44
Show Gist options
  • Save 3rd-Eden/1101736 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/1101736 to your computer and use it in GitHub Desktop.
// change this https://github.com/LearnBoost/socket.io/blob/master/lib/manager.js#L469
if (this.roomClients[id]) {
for (var room in this.roomClients[id]) {
this.rooms[room].splice(this.rooms[room].indexOf(id), 1);
}
}
// to
if (this.roomClients[id]) {
for (var room in this.roomClients[id]) {
this.onLeave(id, room);
}
delete this.roomClients[id]
}
// change
Manager.prototype.onLeave = function (id, room) {
if (this.rooms[room]) {
var index = this.rooms[room].indexOf(id);
if (index >= 0) {
this.rooms[room].splice(index, 1);
}
delete this.roomClients[id][room];
}
};
// to
Manager.prototype.onLeave = function (id, room) {
if (this.rooms[room]) {
var index = this.rooms[room].indexOf(id);
if (index >= 0) {
this.rooms[room].splice(index, 1);
}
if (!this.rooms[room].length) {
delete this.rooms[room];
}
delete this.roomClients[id][room];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment