Compare commits

...

4 Commits

Author SHA1 Message Date
fiatjaf
2f7e3f8473 bump version. 2022-06-22 20:08:48 -03:00
monlovesmango
536dbcbffe Update pool.js 2022-06-22 20:07:25 -03:00
monlovesmango
ed52d2a8d4 updating cb property for subControllers entries
when updating subscription or adding new relays, subsequent events that are received have the relay as undefined. by updating cb property for the subControllers entries to be an arrow function (when calling sub.sub or sub.addRelay), subsequent events now return the relay url appropriately
2022-06-22 20:07:25 -03:00
fiatjaf
faf8e62120 maybe fix a bug with calling sub.sub() 2022-06-04 18:34:54 -03:00
2 changed files with 10 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "nostr-tools",
"version": "0.23.1",
"version": "0.23.4",
"description": "Tools for making a Nostr client.",
"repository": {
"type": "git",

16
pool.js
View File

@@ -26,16 +26,15 @@ export function relayPool() {
const activeSubscriptions = {}
const sub = (
{cb, filter, beforeSend},
id = Math.random().toString().slice(2)
) => {
const sub = ({cb, filter, beforeSend}, id) => {
if (!id) id = Math.random().toString().slice(2)
const subControllers = Object.fromEntries(
Object.values(relays)
.filter(({policy}) => policy.read)
.map(({relay}) => [
relay.url,
relay.sub({filter, cb: event => cb(event, relay.url), beforeSend}, id)
relay.sub({cb: event => cb(event, relay.url), filter, beforeSend}, id)
])
)
@@ -54,12 +53,15 @@ export function relayPool() {
}) => {
Object.entries(subControllers).map(([relayURL, sub]) => [
relayURL,
sub.sub({cb, filter, beforeSend}, id)
sub.sub({cb: event => cb(event, relayURL), filter, beforeSend}, id)
])
return activeSubscriptions[id]
}
const addRelay = relay => {
subControllers[relay.url] = relay.sub({cb, filter}, id)
subControllers[relay.url] = relay.sub(
{cb: event => cb(event, relay.url), filter, beforeSend},
id
)
return activeSubscriptions[id]
}
const removeRelay = relayURL => {