PubKeeper JS Client
This is a PubKeeper client that enables web browsers to join, consume, and produce content on the PubKeeper network. At this time, the JS client is only capable of publishing/consuming WebSocket based transports.
Concepts & Terms
- Brew: the method of delivery - ie. WebSocket / SocketIO
- Brewer: An object that accepts an input and writes to the respective transport
- Patron: A consumer of data from a brewer of a respective transport
Crypto / Sec
Communication to the PubKeeper service is conducted over SSL, which allows the service to deliver to clients information, including the AES key of connected brewers.
All data communicated over the PubKeeper network is encrypted with AES-128 encryption. Creating a new brewer will generate an AES key that will be stored with the central PubKeeper service, and distributed to other authenticated clients of the network.
Local Development
npm install
npm run build
npm run lint
npm run typecheck
npm run test
babel src/ -d lib
Basic Syntax
Brewing Setup
To being to produce data into the PubKeeper network you will need to create a bottle in which data can be filled. Then create brewers to produce that bottle of information. The example below will setup a Brewer with the topic of topic.information
import PubkeeperClient from 'pubkeeper-client';
const pc = new PubkeeperClient();
pc.connect({
socket: {
host: '127.0.0.1',
port: 9898,
room: 'pubkeeper.n.io',
},
jwt: 'your jwt',
}).then(successHandler, errorHandler);
const brew = {
name: 'websocket',
hostname: 'localhost',
port: 9555,
};
pc.addBrew(brew);
State Change Callback (Optional)
This callback will be fired upon these events
- BREWER_NOTIFY
- BREWER_REMOVED
- PATRON_NOTIFY
- PATRON_REMOVED
You will have to import the Packet types and then set the callback
import PubkeeperClient, { Packet } from '@pubkeeper/client';
pc.onStateChange(({ type, obj }) => {
switch (type) {
case Packet.BREWER_NOTIFY:
break;
case Packet.BREWER_REMOVED:
break;
case Packet.PATRON_NOTIFY:
break;
case Packet.PATRON_REMOVED:
break;
default:
break;
}
});
Brewer Setup
const brewer = pc.addBrewer('topic.information');
const brewer2 = pc.addBrewer({ topic: 'topic.information', brews: ['websocket'] });
Brewer validation
A Brewer cannot have a wildcard topic
It will return an errors
array if it did not pass validation which you can display to your users
const brewer = pc.addBrewer('topic.*');
if (brewer.errors) {
alert('Error!');
} else {
this.brewers = [...this.brewers, brewer];
}
Patron Setup
To listen to someone who is brewing information, you need to subscribe to the topic, and configure a callback to occur when there is data available for processing.
const patronConfig = {
topic: 'weather.*',
};
const patron = pc.addPatron(patronConfig, function ({ topic, data }) {
});