fpp

Fanout Pubsub Protocol Library

npm install fpp
9 downloads in the last month

nodefpp - Fanout Pubsub Protocol Library for NodeJS

Version: v 0.1.2
Date: May 15th, 2013
Author: Katsuyuki Ohmuro harmony7@pex2.jp

Description

Fanout Pubsub Protocol library for NodeJS.

The Fanout pubsub protocol is used to send simple realtime messages over a communications channel. This library has been designed for use either with Fanout's pubsub service or any compatible service.

This library implements the FPP data format as a custom data format for pubcontrol, an EPCP library for NodeJS. These data objects created using fpp may also be used with pubcontrol's publisher if desired.

This library also provides some convenience methods that provide simple ways to set up a publisher when working with the Fanout service.

Requirements

pubcontrol

Sample usage

The simple usage of fpp is with Fanout's FPP service. This usage requires a realm name and a base64-encoded realm key, which are available to users of the Fanout service.

// This example uses FPP to send a message through fanout.io

var fpp = require('fpp');

// Authentication / Create Publisher with Fanout
var realmName = "myrealm";          // fanout realm name
var realmKeyBase64 = "###########"; // fanout realm key
var pub = fpp.fanout(realmName, realmKeyBase64);

// Publish message
pub.publish("test", "hello world", function(success, message, context) {
    console.log(success);
    console.log(message);
    console.dir(context);
});

It is also possible to use fpp to send messages over a compatible server. This usage instead requires an endpoint URI.

// This example uses FPP to send a message through
// a custom server that accepts FPP

var fpp = require('fpp');
var pubcontrol = require('pubcontrol');

// Create publisher for endpoint
var endpoint = "http://localhost:1337";
var pub = new fpp.FppPubControl(endpoint);

// Publish message
pub.publish("test", "hello world", function(success, message) {
    console.log(success);
    console.dir(message);
});

If the custom server requires authentication, fpp can use the authentication objects defined in pubcontrol. See pubcontrol documentation for details on creating authentication objects.

// Create publish for endpoint using basic auth
var endpoint = "http://localhost:1337";
var auth = new pubcontrol.Auth.AuthBasic("username", "password");
var pub = new fpp.FppPubControl(endpoint, auth);

License

(C) 2013 Fanout, Inc.
Licensed under the MIT License, see file COPYING for details.

npm loves you