@pubkeeper/browser-client v4.0.4
Pubkeeper Browser Client
@pubkeeper/browser-client
enables web browsers to join, consume, and produce content on a Pubkeeper network. This package is an aggregate package that combines sane defaults for using Pubkeeper in a browser.
Installation
Using npm:
$ npm install --save @pubkeeper/browser-client
Then, load using ES5 require()
syntax…
var PubkeeperClient = require('@pubkeeper/browser-client').PubkeeperClient;
…or with ES2015+ import
syntax:
import { PubkeeperClient, WebSocketBrew } from '@pubkeeper/browser-client';
Browser
<script src="https://unpkg.com/@pubkeeper/browser-client/dist/pubkeeper-browser-client.min.js"></script>
Usage
import { PubkeeperClient, WebSocketBrew } from '@pubkeeper/browser-client';
const client = new PubkeeperClient({
server: `[your pk server]`,
jwt: `[your pk token]`,
brews: [
new WebSocketBrew({
brewerConfig: {
hostname: '127.0.0.1',
port: 9000,
secure: true,
},
}),
],
});
client.connect().then(() => {
console.log('ready!');
});
Adding a Brewer
client.addBrewer('topic.text', (brewer) => {
const id = setInterval(() => { brewer.brewText('Hello World!'); });
return () => { clearInterval(id); };
});
Adding a Patrons
client.addPatron('topic.text', (patron) => {
// is activated
const handler = (uint8, meta) => {
console.log("sender: %s", meta.from);
console.log("topic: %s", meta.topic);
console.log("raw data: %o", uint8);
console.log("text data: %s", new TextDecoder().decode(uint8));
}
patron.on("message", handler);
return () => {
// deactivation/tear-down
patron.off("message", handler);
};
});
Related Packages
- @pubkeeper/client - The core pubkeeper client.
- @pubkeeper/brew-websocket - The WebSocket brew
- @pubkeeper/crypto-cjs-aes-cbc - AES-CBC encryption support
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago