Skip to content

konecty/meteor-user-presence

Repository files navigation

USER PRESENCE

This package monitors the user to track user's state and save 3 fields in user's record:

  • statusDefault - Status setted by user
  • statusConnection - Connection status (offline, online and away)
  • status
    • Offline if statusConnection or statusDefault are offline
    • Same as statusConnection if statusDefault is online
    • Same as statusDefault

How to use

Add package

meteor add konecty:user-presence

Configure client

//CLIENT
Meteor.startup(function() {
	// Time of inactivity to set user as away automaticly. Default 60000
	UserPresence.awayTime = 300000;
	// Set user as away when window loses focus. Defaults false
	UserPresence.awayOnWindowBlur = true;
	// Start monitor for user activity
	UserPresence.start();
});

Start server

//SERVER
// Listen for new connections, login, logoff and application exit to manage user status and register methods to be used by client to set user status and default status
UserPresence.start();
// Active logs for every changes
// Listen for changes in UserSessions and Meteor.users to set user status based on active connections
UserPresenceMonitor.start();

Logs

//SERVER
UserPresence.activeLogs();

Server Methods

// 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');