mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 16:48:50 +00:00
return sub object from .sub() and other methods.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "0.7.2",
|
"version": "0.8.0",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
8
pool.js
8
pool.js
@@ -29,19 +29,23 @@ export function relayPool(globalPrivateKey) {
|
|||||||
const activeFilters = filter
|
const activeFilters = filter
|
||||||
|
|
||||||
activeSubscriptions[id] = {
|
activeSubscriptions[id] = {
|
||||||
sub: ({cb = activeCallback, filter = activeFilters}) =>
|
sub: ({cb = activeCallback, filter = activeFilters}) => {
|
||||||
Object.entries(subControllers).map(([relayURL, sub]) => [
|
Object.entries(subControllers).map(([relayURL, sub]) => [
|
||||||
relayURL,
|
relayURL,
|
||||||
sub.sub({cb, filter}, id)
|
sub.sub({cb, filter}, id)
|
||||||
]),
|
])
|
||||||
|
return activeSubscriptions[id]
|
||||||
|
},
|
||||||
addRelay: relay => {
|
addRelay: relay => {
|
||||||
subControllers[relay.url] = relay.sub({cb, filter})
|
subControllers[relay.url] = relay.sub({cb, filter})
|
||||||
|
return activeSubscriptions[id]
|
||||||
},
|
},
|
||||||
removeRelay: relayURL => {
|
removeRelay: relayURL => {
|
||||||
if (relayURL in subControllers) {
|
if (relayURL in subControllers) {
|
||||||
subControllers[relayURL].unsub()
|
subControllers[relayURL].unsub()
|
||||||
if (Object.keys(subControllers).length === 0) unsub()
|
if (Object.keys(subControllers).length === 0) unsub()
|
||||||
}
|
}
|
||||||
|
return activeSubscriptions[id]
|
||||||
},
|
},
|
||||||
unsub: () => {
|
unsub: () => {
|
||||||
Object.values(subControllers).forEach(sub => sub.unsub())
|
Object.values(subControllers).forEach(sub => sub.unsub())
|
||||||
|
|||||||
Reference in New Issue
Block a user