Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

Group count never gets decreased #78

Closed gtramontina closed 13 years ago

gtramontina commented 13 years ago

Currently when a user disconnects, the groups where they were in don't update the user count. I believe it is expected that whenever a user disconnects, whichever groups they were in should decrease the user count number.

ericz commented 13 years ago

Hi gtramontina,

That is indeed the expected behavior. Can you show me the code you have that causes this? I can't seem to reproduce the bug.

Eric

gtramontina commented 13 years ago

Sure, here is what I have (it is written in coffee, btw): When a client connects to my app, the client-side code does the following:

now.joinRoom
  id: roomId,
  iAmIn

Then the server-side gets/creates a group and add the user to it:

everyone = nowjs.initialize app
everyone.now.joinRoom = (roomInfo, callback) ->
  room = nowjs.getGroup roomInfo.id
  room.addUser @user.clientId
  callback()

This actually works! If I do 'room.count' it'll give me the number of users in that room. The problem I'm facing is, when the user disconnects (websocket connection closed - they close the browser, for example), the room count doesn't get decremented.

I can workaround this by either

So here is what my expectation was: whenever a user gets disconnected, either automatically decrements the counter or trigger the 'on disconnect' event of each room the user was in.

Thanks for your support!

ericz commented 13 years ago

Hi gtramontina,

I agree with your expected behavior. The library should already be doing that.

For me count does indeed decrement when the browser is closed or otherwise connection is terminated. Are you on the latest version of NowJS? there was a bug that was fixed in this commit: https://github.com/Flotype/now/commit/e9deb76acdf56470025c2c83b39a340ab4a3de05#lib/nowServerLib.js that would cause the bug you describe.

Eric

ericz commented 13 years ago

Closing issue, can't replicate. Feel free to reopen if you discover more details gtramontina.

Thanks, Eric

gtramontina commented 13 years ago

Oops, sorry about not getting back to you. I didn't have a chance to test it again with a newer version, but if you say it works, it works! :-) Thanks!

Update: It really works! Thanks! And the group.on 'connect'/'disconnect 'events work as well! Thanks a lot!