Skip to content

Instantly share code, notes, and snippets.

@aashay
Created April 24, 2011 23:28
Show Gist options
  • Save aashay/939974 to your computer and use it in GitHub Desktop.
Save aashay/939974 to your computer and use it in GitHub Desktop.
NowJS ClientGroup .on "bug"
24 Apr 16:27:32 - Client 8192318114452064 connected
Adding 8192318114452064. Counter is 0
24 Apr 16:27:39 - Initializing client with transport "websocket"
24 Apr 16:27:39 - Client 4147976329550147 connected
Adding 4147976329550147. Counter is 1
Adding 4147976329550147. Counter is 2
24 Apr 16:27:53 - Initializing client with transport "websocket"
24 Apr 16:27:53 - Client 015604767017066479 connected
Adding 015604767017066479. Counter is 3
Adding 015604767017066479. Counter is 4
Adding 015604767017066479. Counter is 5
var counter = 0;
everyone.now.doGroupTest = function(){
var group = nowjs.getGroup("FOO");
group.on('connect', function(){
console.log("Adding " + this.user.clientId + ". Counter is " + counter);
counter++;
});
group.addUser(this.user.clientId);
}
@aashay
Copy link
Author

aashay commented Apr 24, 2011

Steps to reproduce:

  1. Open a browser (that has a button that will trigger doGroupTest). Hit the button to fire the method.
  2. Open another browser. Do this again.
  3. Open a third browser. Do it again.
    Rather than incrementing the counter one time (so that counter is 3), it increments every time PER connection. There are only three clients connected but the "connect" event is fired a lot more than it should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment