GithubHelp home page GithubHelp logo

faye-presence's Introduction

Faye Presence Build Status

Presence channels are an addition to Faye implemented via an extension and monitoring Faye events.

Getting Started

Install faye-presence:

$ npm install faye-presence --save

After creating your Faye server, install the faye-presence plugin:

var presence = require('faye-presence');

//...

var faye = new Faye.NodeAdapter(options);
presence.setup(faye, faye.getClient(), {
  servers: [ 'localhost:6379' ]
});

servers is an array of redis hostname/ports to use for storing presence data.

When a user subscribes to a channel starting with /presence/, they should also include in the message some presence information. (This is done using a Faye client plugin.) The outgoing subscription message should include an ext field that looks like this:

{
  ext: {
    presence: {
      id: 'username',
      data: {
        name: 'John Doe',
        avataur: 'http://example.com/avatar.png'
      }
    }
  }
}

The data field is optional and can be a javscript object with whatever information you want. It is persisted in Redis as long as that client is subscribed to that channel.

The subscription confirmation message from the server will then include a list of everyone current subscribed to that channel. Again, this needs to be intercepted using a client plugin:

{
  ext: {
    presence: {
      subscribe: {
        $id: $data,
        $id: $data,
        ...
      }
    }
  }
}

Whenever somebody new subscribes or unsubscribes from the channel, a message will be posted to the channel and delivered to all subscribers:

{
  subscribe: {
    $id: $data,
    ...
  },
  unsubscribe: {
    $id: null,
    ...
  }
}

The presence id is used instead of the internal Faye client id because it can more accurately identify an entity, where the Faye client id identifies a connection. A user can be subscribed concurrently on several browsers, and will not show as unsubscribed until all connections are closed.

Running tests:

Using docker-compose:

docker-compose run node npm test

faye-presence's People

Contributors

zwily avatar

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.