ostrio:user-status

v0.6.0Published 10 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.

Install:

meteor add ostrio:user-status

ES6 Import:

1import { UserStatus } from 'meteor/ostrio:user-status';

Usage

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

RectiveVar UserStatus.status can be used to identify current user's status

1import { UserStatus } from 'meteor/ostrio:user-status';
2UserStatus.status.get(); // One of offline, online, idle

Session UserStatusIdle can be used to identify if user currently is idle

1Session.get('UserStatusIdle'); // Boolean true when user is idle

Updated user's object

1{
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    },
10    online: Boolean, //-> Is user online
11    idle: Boolean,   //-> Is user online but idle
12    lastLogin: Date  //-> Current or last login time
13  },
14  connection: String //-> Current or last used DDP Connection ID
15};

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)

1<template name="pause">
2  <h1>You are on pause</h1>
3</template>

Create routes (routes.coffee)

1/*
2 * Catch all routes
3 */
4Router.onBeforeAction(function() {
5  Meteor.wrapAsync(function(route) {
6    if (!route.route.options.omitted) {
7      Session.set('prev_href', route.url);
8    }
9  });
10});
11
12
13/*
14 * Example route map
15 */
16Router.map(function() {
17  this.route('index', {
18    template: 'index',
19    path: '/'
20  });
21  this.route('pause', {
22    template: 'pause',
23    path: '/pause',
24    omitted: true
25  });
26});
27
28
29/*
30 * Check wherever user is idle, redirect him to `/pause`, 
31 * if user is active again redirect to previous URL
32 */
33Tracker.autorun(function() {
34  if (Session.get('UserStatusIdle')) {
35    Session.set('UserStatusOnPause', true);
36    Router.go('/pause');
37  } else if (!Session.get('UserStatusIdle') && Session.get('UserStatusOnPause')) {
38    Session.set('UserStatusOnPause', false);
39    Router.go(Session.get('prev_href'));
40  }
41});