Leave event

33 views
Skip to first unread message

Ben Corne

unread,
Jul 2, 2012, 5:39:17 PM7/2/12
to no...@googlegroups.com
Hi, I'm trying to figure out how to use group's leave event.

It seems to me that when a user disconnects, or leaves a group via group.removeUser(clientId), it emits the leave event BEFORE the user is removed from the group.
Is there an event that is fired AFTER the user is removed from the group, because I need to know what, in order to give an accurate count of how many are in the group.

Kind regards.
Ben

Ian Serlin

unread,
Jul 6, 2012, 1:31:42 PM7/6/12
to no...@googlegroups.com
Hi Ben,

No there is not, if you look at group.js you can see "leave" being emitted before the user is actually removed from the group. For your case I would fork the nowjs code and add your own "left" event, e.g. on line 216 of group.js you could add:

self.emit.call(clientId, 'left');

after the two delete statements.

Ben Corne

unread,
Jul 7, 2012, 6:59:19 AM7/7/12
to no...@googlegroups.com
Thanks, that will do the trick.

Perhaps an idea to document this better in the API:  http://nowjs.com/doc/symbols/Group#event:leave  (says: leave() Called in the context of a user who has just been removed from the group.) indicating the user is removed away from the group by the time you get this event.

Kind regards
Ben

On Friday, July 6, 2012 7:31:42 PM UTC+2, Ian Serlin wrote:
Hi Ben,

No there is not, if you look at group.js you can see "leave" being emitted before the user is actually removed from the group. For your case I would fork the nowjs code and add your own "left" event, e.g. on line 216 of group.js you could add:

self.emit.call(clientId, 'left');

after the two delete statements.

Ian Serlin

Ian Serlin

unread,
Jul 7, 2012, 11:11:40 PM7/7/12
to no...@googlegroups.com
Good point, I'll bring it up with the Flotype guys!

Ben Corne

unread,
Jul 9, 2012, 3:25:11 AM7/9/12
to no...@googlegroups.com
One more question:

How do I require the server module when I compile it myself? I forked now from github and made a change to group.js.
Then I typed make in the base directory, which updated dist/now.js. But it contains the client-side code (uses window global var).
So I tried editting bin/build.js to have base node_client instead of client, but that gives something that doesn't work.

checked this: http://howtonode.org/how-to-module but it didn't tell me much more about the build process of a library that's both serverside and clientside.

Any help appreciated.
Kind regards
Ben


On Friday, July 6, 2012 7:31:42 PM UTC+2, Ian Serlin wrote:

Ian Serlin

unread,
Jul 9, 2012, 3:57:48 PM7/9/12
to no...@googlegroups.com
Hey Ben,

You actually don't need to build anything. In the package.json file for your project, just replace the nowjs line in the dependencies section that looks like:

"now": ">= 0.8.1"

with:


replacing that git url with your fork of now. After that, remove the existing now folder from your app's node_modules folder. Then you can do an "npm install" in your app's directory from the terminal and you should get your version of nowjs installed which you can use exactly the same as the official version, e.g. var now = require('now');


Reply all
Reply to author
Forward
0 new messages