Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dburles/meteor-presence
👥 Meteor package to help track users' presence
https://github.com/dburles/meteor-presence
meteor meteor-package
Last synced: 6 days ago
JSON representation
👥 Meteor package to help track users' presence
- Host: GitHub
- URL: https://github.com/dburles/meteor-presence
- Owner: dburles
- License: mit
- Created: 2013-12-03T23:28:06.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-26T02:02:45.000Z (almost 9 years ago)
- Last Synced: 2024-04-13T17:16:42.626Z (7 months ago)
- Topics: meteor, meteor-package
- Language: JavaScript
- Homepage: http://atmospherejs.com/tmeasday/presence
- Size: 408 KB
- Stars: 87
- Watchers: 8
- Forks: 21
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- License: License.txt
Awesome Lists containing this project
README
# Meteor Presence
A very simple presence package, to track who's online, etc.
## Installation
``` sh
$ meteor add tmeasday:presence
```## Usage
Once added to your project, a new Meteor collection called `Presences` is available.
All active connections are then stored in this collection. A presence document from an authenticated user will contain their user id on the `userId` field.
NOTE: The package doesn't publish the presences by default, you'll need to do something like:
```js
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 }});
});
```And of course, don't forget to subscribe.
```js
Meteor.subscribe('userPresence');
```## State function
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'`):
```js
// Setup the state function on the client
Presence.state = function() {
return {
currentRoomId: Session.get('currentRoomId')
};
}
```Now we can simply query the collection to find all other users that share the same currentRoomId
```js
Presences.find({ state: { 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