EOSE nip-15

This commit is contained in:
Leo Wandersleb
2022-09-29 00:02:31 -03:00
committed by fiatjaf
parent 896af30619
commit 1f1bcff803
2 changed files with 49 additions and 33 deletions

View File

@@ -26,7 +26,7 @@ export function relayPool() {
const activeSubscriptions = {}
const sub = ({cb, filter, beforeSend}, id) => {
const sub = ({cb, filter, beforeSend}, id, cbEose) => {
if (!id) id = Math.random().toString().slice(2)
const subControllers = Object.fromEntries(
@@ -34,7 +34,8 @@ export function relayPool() {
.filter(({policy}) => policy.read)
.map(({relay}) => [
relay.url,
relay.sub({cb: event => cb(event, relay.url), filter, beforeSend}, id)
relay.sub({cb: event => cb(event, relay.url), filter, beforeSend}, id,
cbEose)
])
)
@@ -60,7 +61,7 @@ export function relayPool() {
const addRelay = relay => {
subControllers[relay.url] = relay.sub(
{cb: event => cb(event, relay.url), filter, beforeSend},
id
id, () => cbEose(relay.url)
)
return activeSubscriptions[id]
}