update readme for protocol update

This commit is contained in:
Richard Bondi 2021-02-21 14:10:55 -06:00
parent c13772c258
commit 710a3c3ce1
No known key found for this signature in database
GPG Key ID: FB0E9BFF77E167D3
1 changed files with 30 additions and 15 deletions

View File

@ -14,27 +14,42 @@ pool.setPrivateKey('<hex>') // 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: '<hex>'}})
// or bulk follow
pool.sub({cb:(event, relay) => {...}, filter: {authors: ['<hex1>', '<hex2>', ..., '<hexn>']}})
// get specific event
pool.sub({cb: (event, relay) => {...}, filter: {id: '<hex>'}})
// 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('<hex>')
pool.subKey('<hex>')
pool.subKey('<hex>')
pool.reqFeed()
pool.reqEvent({id: '<hex>'})
pool.reqKey({key: '<hex>'})
// upon request the events will be received on .onEvent above
// publishing events:
pool.publish(<event object>)
// 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('<url>')
// 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).