konecty/meteor-user-presence

Callbacks?

Closed this issue · 7 comments

Is there a callback I can call when a user goes online/offline?

In my case, I want to set up an eventlistener when a user gets online, and detach it again when they go offline

There isn't the callback you want.

Do you need this at server or client side?

Great package, using with multiple instances... I would also find this helpful server side.

@stefankutko can you show me your use case for callbacks at server side?

I want to attach an event listener to a user once online, and detach it upon going offline

Something like:

UserStatus.onConnect(function(user) {
  SomeCollection.startTwitterStream(user);
});

UserStatus.onDisconnect(function(user) {
  SomeCollection.stopTwitterStream(user);
});

@madshargreave at server side?

Yes server side

Ok, now you can: https://github.com/Konecty/meteor-user-presence/blob/master/server%2Fmonitor.js#L2

On new version (1.2.6) you can use:

UserPresenceMonitor.onSetUserStatus = function(user, status, statusConnection) {
  // code
}