Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oakfang/peerq
A p2p queue using a coven broker
https://github.com/oakfang/peerq
Last synced: 6 days ago
JSON representation
A p2p queue using a coven broker
- Host: GitHub
- URL: https://github.com/oakfang/peerq
- Owner: oakfang
- License: mit
- Created: 2018-04-10T06:31:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-10T14:32:43.000Z (almost 7 years ago)
- Last Synced: 2024-12-10T19:47:38.104Z (about 1 month ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# peerq
A p2p queue using a coven broker## Install
`yarn add peerq`## Usage
```ts
const PeerQueue = require('peerq');const peerq = new PeerQueue({
host: 'localhost', // Your coven-broker host
port: 4000, // Your coven-broker port
secure: false, // is your broker using wss?
room: 'dev', // Use this coven room for the queue
password: '123456', // encrypt all queue messages with this password (messages that can't be decrypted are dropped)
});type UUID = string;
type CovenID = UUID;
type PeerqClientID = UUID;
type Timestamp = number;
type PeerqMessagePayload = any;
type PeerqMessage = {
$origin: CovenID;
$id: PeerqClientID;
dt: Timestamp;
topic: string;
payload: PeerqMessagePayload;
};// peerq.publish([topic: string], payload: PeerqMessagePayload) -> Promise
peerq.publish({ user: 'foo' }).then(() => {
// message was published to queue...
});// peerq.waitForPeers(peerNumber: number) -> Promise
peerq.waitForPeers(1).then(() => {
// there's at least one other peer using the queue
// this DOES NOT guarantee that peer can read/write your encrypted messagesconsole.log(peerq.size); // peerq.size -> number, number of active peers
});// peerq.request([topic: string], payload: PeerqMessagePayload) -> Promise
peerq.request({ user: 'foo' }).then(response => {
// a client responded (see below) to your request.
});type MessageStreamOptions = {
// exclude your own messages. default: false
excludeSelf: boolean;
};// peerq.getMessageStream(options?: MessageStreamOptions) -> Observable
const message$ = peerq.getMessageStream()
.filter(({ payload }) => payload.user && payload.user === 'foo')
.observe(async msg => {
// peerq.respond(msg: PeerqMessage, response: PeerqMessagePayload) -> Promise
await peerq.respond(msg, 'meow');
// response sent!
});
```