Skip to content

mlebrun/notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notify

Build Status Coverage Status

A pub/sub plugin for Primus.

Installation

npm install mlebrun/notify --save

Usage

Server

To use the pub/sub functionality, simply use Notify after Primus Emit and Primus Rooms.

var Notify = require('notify');
var Subscriber = require('notify-redis-subscriber');

var config = {
  port: 34000,
  transformer: 'engine.io',
};

// pass in subscriber via config
config.subscriber = new Subscriber();

var primus = new Primus(server, config);
primus.use('notify', Notify);

When a subscriber a receives an event from that key, it will forward that event to the client. The event that is fired should be structured as so:

subscriber.emit('message', 'my-key', { "type": "some-event", "data": { "...any extra event data" } });

Client

From the client we just emit keys we want to subscribe to.

var socket = new Primus();

socket.on('open', function() {
  // subscribe to a key
  this.emit('subscribe', 'my-key');
});

// listen for specific events from that key
socket.on('some-event', function() {
  console.log( 'Hi!' );
});

All that is needed is to select a pre-built Subscriber or provide your own.

Writing a custom adapter is easy. This one wraps Redis.

About

A pluggable Pub/Sub module for Primus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published