pubsub
PubSub for Node and the Browser.
Last updated 4 years ago by mdwisniewski .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install pubsub 
SYNC missed versions from official npm registry.

Installation

Install and save the pubsub module. npm i --save pubsub

Or use with script tag <script type="text/javascript" src="https://gitlab.me/wski/pubsub/raw/master/dist.js"></script>

Then simply require it at the root level of your project.

require('pubsub');

Usage

Join a channel

PubSub.join('general', (message, uuid) => {
  // Upon joining you will receive a uuid without a message.
  // Other times, you will be sent a message, and a uuid.
  if (message)
    console.log(`${uuid} recived message`, message);
});

Leave a channel

// You can leave the channel by passing the uuid provided in join.
PubSub
  .leave('general', uuid)
  .then(() => {
    // successfully left channel
  });

Publish to a channel

PubSub
  .publish('general', {test: 'passed'})
  .then(() => {
    // message sent to all subscribers
  });

Enable cross tab communication (for web applications)

PubSub.setFlag('crossTabEnabled', true);

Enable history

PubSub.setFlag('historyEnabled', true);

Increase history limit (default 15)

PubSub.setFlag('historyLength', 30);

Get history

PubSub.history('general', 15); // Returns 15 messages from history

Example

JSFiddle.net example

Current Tags

  • 3.2.1                                ...           latest (4 years ago)

30 Versions

  • 3.2.1                                ...           4 years ago
  • 3.2.0                                ...           4 years ago
  • 3.1.8                                ...           4 years ago
  • 3.1.2                                ...           4 years ago
  • 3.1.1                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.6                                ...           4 years ago
  • 3.0.5                                ...           4 years ago
  • 3.0.4                                ...           4 years ago
  • 3.0.3                                ...           4 years ago
  • 3.0.2                                ...           4 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.1.7                                ...           5 years ago
  • 2.1.6                                ...           5 years ago
  • 2.1.5                                ...           5 years ago
  • 2.1.4                                ...           5 years ago
  • 2.1.3                                ...           5 years ago
  • 2.1.2                                ...           5 years ago
  • 2.1.1                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.2                                ...           7 years ago
  • 0.0.6                                ...           7 years ago
  • 0.0.5                                ...           7 years ago
  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           7 years ago
  • 0.0.1-security                                ...           5 years ago
  • 1.0.0                                ...           5 years ago

Copyright 2014 - 2017 © taobao.org |