hiranya / websub-hub

A WebSub Hub implementation in Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSub-Hub

npm version Build Status npm version stability

A WebSub Hub implementation in Node.js

Expectations

  • Highly performant: A single node can handle thousands of subscriptions.
  • Scalable: Scale the hub in minutes. We choose monogdb as distributed storage.
  • Efficient: Only distribute delta updates.
  • Websocket: Use websockets to get updates in realtime.
  • Standardized We're trying to be compliant with the W3C WebSub specification.
  • Developer friendly Provide an easy interface to configure and use the hub.

Specification

https://w3c.github.io/websub/

Installation

$ docker run -d -p 27017:27017 -p 28017:28017 -e AUTH=no tutum/mongodb
$ npm i -g webpub-server
$ websub-hub -l info -m mongodb://localhost:27017/hub

Getting started

$ node examples\server.js
$ node examples\feed.js
$ node examples\callback.js

Subscribe

As soon as you want to subscribe to a topic you can initiate a subscription request. The subscriber has to verify that action as mentioned above.

const Subscriber = require('websub-hub').subscriber
const s = new Subscriber({ hubUrl: 'http://127.0.0.1:3000' })
s.subscribe({
  topic: 'http://127.0.0.1:6000',
  callbackUrl: 'http://127.0.0.1:5000'
}).then((response) => {})

Unsubscribe

const Subscriber = require('websub-hub').subscriber
const s = new Subscriber({ hubUrl: 'http://127.0.0.1:3000' })
s.unsubscribe({
  topic: 'http://127.0.0.1:6000',
  callbackUrl: 'http://127.0.0.1:5000'
}).then((response) => {})

Publish

const Publisher = require('websub-hub').publisher
const p = new Publisher({ hubUrl: 'http://127.0.0.1:3000' })
p.publish('http://127.0.0.1:6000').then((response) => {})

Test

$ npm run test

About

A WebSub Hub implementation in Node.js

License:MIT License


Languages

Language:JavaScript 100.0%