GithubHelp home page GithubHelp logo

nikolayh86 / meteor-presence Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dburles/meteor-presence

0.0 2.0 1.0 114 KB

Meteor package to help track users' presence

Home Page: http://atmospherejs.com/package/presence

License: MIT License

JavaScript 100.00%

meteor-presence's Introduction

Meteor Presence

A very simple presence package, to track who's online, etc.

Important

This version of presence has been re-written from the ground up to make use of the new Meteor connection API. If you're using a version of Meteor prior to 0.7.0, you should use the 0.3.0 version. Add to your smart.json:

"packages": {
  "presence": "0.3.0"
}

Installation

The Presence package can be installed with Meteorite. From inside a Meteorite-managed app:

$ mrt add presence

Usage

The user's online state can be tracked via the Presences collection, referenced by userId

NOTE: The package doesn't publish the presences by default, you'll need to do something like:

Meteor.publish('userPresence', function() {
  // Setup some filter to find the users your user
  // cares about. It's unlikely that you want to publish the 
  // presences of _all_ the users in the system.
  
  // If for example we wanted to publish only logged in users we could apply:
  // filter = { userId: { $exists: true }};
  var filter = {}; 
  
  return Presences.find(filter, {fields: {state: true, userId: true}});
});

To use that presence, you can inspect the Presences collection in the client.

Advanced Usage

State functions

If you want to track more than just users' online state, you can set a custom state function. (The default state function returns just 'online'):

// Setup the state function on the client
Presence.state = function() {
  return {
    online: true,
    currentRoomId: Session.get('currentRoomId')
  };
}

Now we can simply query the collection to find all other users that share the same currentRoomId

Presences.find({ state: { online: true, currentRoomId: Session.get('currentRoomId') } })

Of course presence will call your function reactively, so everyone will know as soon as things change.

Contributing

Please! The biggest thing right now is figuring how to write tests.

License

MIT

meteor-presence's People

Contributors

dburles avatar daltonrenaldo avatar dsyko avatar nikolayh86 avatar

Watchers

James Cloos avatar  avatar

Forkers

eliga

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.