mesh-pubnub
pubnub adapter
Last updated 4 years ago by architectd .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mesh-pubnub 
SYNC missed versions from official npm registry.

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.operation("anotherCommandToIgnore"));

db.addChannel(channel)

adds a new channel to subscribe to.

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

stream.Readable db(operationName, options)

Publishes a new operation to pubnub.

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

stream.Readable db(tail, filter)

Tails a remote operation. This is your subscription function.

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

});

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 operations on lokidb - pass to pubnub
db(mesh.operation("tail")).pipe(mesh.open(pubdb));

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

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

Current Tags

  • 2.0.1                                ...           latest (4 years ago)

3 Versions

  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (8)
Dev Dependencies (19)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |