From 710a3c3ce1030f2979590f833c5bae09f45ba873 Mon Sep 17 00:00:00 2001 From: Richard Bondi Date: Sun, 21 Feb 2021 14:10:55 -0600 Subject: [PATCH] update readme for protocol update --- README.md | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5d7e15c..ac245ce 100644 --- a/README.md +++ b/README.md @@ -14,27 +14,42 @@ pool.setPrivateKey('') // optional pool.addRelay('ws://some.relay.com', {read: true, write: true}) pool.addRelay('ws://other.relay.cool', {read: true, write: true}) -pool.onEvent((event, context, relay) => { - console.log(`got a relay with context ${context} from ${relay.url} which is already validated.`, event) +// example callback function for a subscription +function onEvent(event, relay) => { + console.log(`got an event from ${relay.url} which is already validated.`, event) +} + +// subscribing to a single user +// author is the user's public key +pool.sub({cb: onEvent, filter: {author: ''}}) + +// or bulk follow +pool.sub({cb:(event, relay) => {...}, filter: {authors: ['', '', ..., '']}}) + +// get specific event +pool.sub({cb: (event, relay) => {...}, filter: {id: ''}}) + +// get all events +pool.sub({cb: (event, relay) => {...}, filter: {}}) + +// get recent events +pool.sub({cb: (event, relay) => {...}, filter: {since: timestamp}}) + +// publishing events(inside an async function): +const ev = await pool.publish(eventObject, (status, url) => { + if (status === 0) { + console.log(`publish request sent to ${url}`) + } + if (status === 1) { + console.log(`event published by ${url}`, ev) + } }) - -// subscribing to users and requesting specific users or events: -pool.subKey('') -pool.subKey('') -pool.subKey('') -pool.reqFeed() -pool.reqEvent({id: ''}) -pool.reqKey({key: ''}) -// upon request the events will be received on .onEvent above - -// publishing events: -pool.publish() // it will be signed automatically with the key supplied above // or pass an already signed event to bypass this // subscribing to a new relay pool.addRelay('') -// will automatically subscribe to the all the keys called with .subKey above +// will automatically subscribe to the all the events called with .sub above ``` For other utils please read the source (for now).