Skip to content

Instantly share code, notes, and snippets.

@guiocavalcanti
Created June 10, 2011 11:59
Show Gist options
  • Save guiocavalcanti/1018700 to your computer and use it in GitHub Desktop.
Save guiocavalcanti/1018700 to your computer and use it in GitHub Desktop.
this.bind('pusher_internal:member_added', function(data){
var timeoutMember = this.members.get(data.user_id);
if(timeoutMember && timeoutMember.info.timeoutID){ // The member is present with a timeout
clearTimeout(timeoutMember.info.timeoutID);
}else{
var member = this.members.add(data.user_id, data.user_info);
this.dispatch_with_all('pusher:member_added', member);
}
}.scopedTo(this))
this.bind('pusher_internal:member_removed', function(data){
var that = this;
var member = this.members.remove(data.user_id); // temporally removing
member.info.timeoutID = setTimeout(function(){
var member = that.members.remove(data.user_id);
if (member) {
that.dispatch_with_all('pusher:member_removed', member);
}
}, 10000);
// Adding again with the timeout attribute
this.members.add(member.id, member.info);
}.scopedTo(this))
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment