mesh-pubnub-bus

1.0.4 • Public • Published

Build Status Coverage Status Dependency Status

A streamable interface for Pubnub. This library also works nicely with mesh, and other mesh adapters.

Example

var pubnub      = require("mesh-pubnub");
var memory      = require("mesh-memory");
var mesh        = require("mesh");

var mem = mesh.tailable(memory());

var pubnub = mesh.reject("load", pubnub({
  subscribeKey: "sub key"
  publishKey: "pub key",
  channel: "streamChannel"
}, mem);


mem(mesh.op("tail")).pipe(mesh.open(pubnub));

db pubnub(options, responseBus)

Creates a new pubnub streamer.

  • options
    • subscribeKey - your pubnub subscription key
    • publishKey - your pubnub publish key
    • channel - (optional) the channel to subscribe to
  • responseBus - set of commands to reject - default is [load]
var pubStream = pubnub({
  subscribeKey: "sub key"
  publishKey: "pub key",
  channel: "streamChannel"
}, memoryBus);

// does not get broadcasted
pubStream(mesh.action("anotherCommandToIgnore"));

db.addChannel(channel)

adds a new channel to subscribe to.

pubStream.addChannel(mesh.action("someChannel"));
pubStream.addChannel(mesh.action("anotherChannel")_;

stream.Readable db(actionName, options)

Publishes a new action to pubnub.

pubStream({ name: "hello", data: { name: "world" }});
pubStream({ name "doSomething", data: { name: "world" }});

stream.Readable db(tail, filter)

Tails a remote action. This is your subscription function.

db({ name: "tail" }).on("data", function(action) {

});

Or you can do something like synchronizing databases between clients:

var mesh   = require("mesh");
var loki   = require("mesh-loki");
var pubnub = require("mesh-pubnub");

var pubdb = pubnub({
  subscribeKey: "sub key"
  publishKey: "pub key",
  channel: "streamChannel"
});

var db = mesh.tailable(loki());

// listen for local actions on lokidb - pass to pubnub
db(mesh.action("tail")).pipe(mesh.open(pubdb));

// listen for remote actions on pubnub - pass to lokidb
pubdb(mesh.action("tail")).pipe(mesh.open(db));

// stored in loki & synchronized across clients
db(mesh.action("insert", { data: { name: "Juice" }}));

Readme

Keywords

none

Package Sidebar

Install

npm i mesh-pubnub-bus

Weekly Downloads

1

Version

1.0.4

License

ISC

Last publish

Collaborators

  • crcn