diff options
Diffstat (limited to 'src/nostr.js')
| -rw-r--r-- | src/nostr.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/nostr.js b/src/nostr.js index d0df2fb..431bb1e 100644 --- a/src/nostr.js +++ b/src/nostr.js @@ -178,6 +178,14 @@ export class NostrSync { try { return await pool.querySync(this.relays, filter, { maxWait }); } catch { return []; } } + // Live subscription; returns an unsubscribe function. + subscribeEvents(filter, onEvent) { + try { + const sub = pool.subscribeMany(this.relays, [filter], { onevent: onEvent }); + return () => { try { sub.close(); } catch {} }; + } catch { return () => {}; } + } + // Fetch the newest decrypted state across relays, or null. async fetch() { if (!this.sk) return null; |
