Track Online/Offline of a User

Hi Everyone,

I am using Konecty:user-presence for detecting whether a user is online or offline, However, it also comes with a good example but it’s using Accounts UI Package, I don’t want to user accounts UI.

The very same Github repo have the methods like


/ Create a new connection, this package do this automaticly
Meteor.call('UserPresence:connect');
// Set connection as away, can be usefull call this method if you are using cordova to ser user as away when application goes to background for example.
Meteor.call('UserPresence:away');
// Set connection as online
Meteor.call('UserPresence:online');
// Changes the default status of user
Meteor.call('UserPresence:setDefaultStatus', 'busy')

But these methods run automatically, I don’t see any method where I could pass the userId for which I want to track the online/offline status.

Please let me know if I could modify this library a bit and could do what I wish to do. Any help would be greatly appreciated.


^ this is the package i ended up using for detecting user presence. It was useful for me because it allows you to hook into the connect and disconnect events. Not 100% sure what you’re trying to accomplish but this one has methods for turning the user monitor on/off.

1 Like

That’s a good, basic package. The only thing you need to be aware of is that it won’t work correctly if you run multiple server instances (for example, in a scale-out).

1 Like

Fork the repo and add a stop function in server/monitor.js

start: function() {
		this.handle = UsersSessions.find({}).observe({
			added: function(record) { ....
			},
			changed: function(record) { ....
			},
			removed: function(record) { ....
			},
		});
	},
stop: function() {
           if (this.handle) this.handle.stop();
    }

and submit PR when tested

Not to toot my own horn, but My socialize:user-presence package is pretty fantastic. It does not depend on accounts-ui, it’s configurable so you aren’t locked into storing your user’s status on the user’s profile key in the user record (use socialize:user-profile if you want to store a profile and the status on it), AND it scales to multiple servers.

Any features that you feel are necessary that the package doesn’t already enable can be opened as issues for discussion on GitHub.

3 Likes

Thanks @copleykj, I have implemented some other solution for the same.