v0.2.0Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Meteor user status

Reactively setup user's [on|off]line and idle status into Meteor.user().profile.online, returns Boolean value.


meteor add ostrio:user-status


Simply add and use with accounts-base and accounts-password packages, ostrio:user-status will work just behind it on the background, - doesn't requires any setting up

Updated user's object

1User = 
2  username: String
3  emails: [Object]
4  createdAt: Date
5  updatedAt: Date
6  profile:
7    location:
8      ip: String # --> Current or last used user's IP
9    online: Boolean # --> Is user online
10    idle: Boolean # --> Is user online but idle
11  connection: String # --> Current or last used DDP Connection ID

Idle Status

Why idle?: Some apps require your constant attention. Such apps often include games, media players, anything that is CPU/battery intensive, and so on. For these kinds of apps, it may be important (as well as user-friendly) to do something when a user is no longer actively interacting with your app.

To control idle status in current client use Session.get('UserStatusIdle')

For example, let's redirect idle users to almost blank page, using iron-router package: Pause Template (pause.jade)

  h1.center You are on pause

Create routes (routes.coffee)

2@description Catch all routes
4Router.onBeforeAction ->
5  Meteor.wrapAsync( (route) ->
6    if !route.route.options.omitted
7      Session.set 'prev_href', route.url
10@description Create route map
12Router.map ->
13  @route 'index',
14    template: 'index'
15    path: '/'
17  @route 'pause',
18    template: 'pause'
19    path: '/pause'
20    omitted: true
23@description Check wherever user is idle, redirect him to `/pause`, 
24             if user is active again redirect to previous URL
26Tracker.autorun ->
27  if Session.get 'UserStatusIdle'
28    Session.set 'UserStatusOnPause', true
29    Router.go('/pause')
30  else if !Session.get('UserStatusIdle') and Session.get 'UserStatusOnPause'
31    Session.set 'UserStatusOnPause', false
32    Router.go(Session.get('prev_href'))