friendship

0.2.0 • Public • Published

Friendship Build Status Coverage Status NPM version

Friends Manager for your application, will manage relationships between userids and a socketid, which could b-e used with Socket.io to manage the online and offline friends in real time.

Getting Started

npm install friendship --save-dev

Create a friendship Manager

var Friendship = require('friendship');
 
var friendship = new Friendship({
  expire: 3000 //auto checkouts in 3 seconds
});

Register friends of user with id "uid1"

friendship.register('uid1', ['uid2', 'uid3', 'uid4']);

CheckIn of a user with a Socket

friendship.checkin('uid1', 'socketId');

After the expire time (set on initialization), this socket will do a checkout unless a .check() is run before it.

Check to reset expiration

friendship.check('uid1', 'socketId');

Checkout of a user socket

friendship.checkout('uid1', 'socketId');

Can also run a checkout of all sockets that it could have:

friendship.checkout('uid1');

Unregister friends of a user

friendship.unregister('uid1');

This will run a checkout of all sockets and remove the user from any relationship. Can be used to make the user to an offline state on every socket.

TODO

  • Add option to use Redis store.
  • A way to clear all.

Contribute

  1. Fork this repo
  2. run npm install
  3. Create the tests for the new functionality or bug case
  4. Put your awesome code
  5. run grunt test
  6. All good?, place a pull request

Readme

Keywords

none

Package Sidebar

Install

npm i friendship

Weekly Downloads

3

Version

0.2.0

License

MIT

Last publish

Collaborators

  • pjnovas