Skip to content

Commit

Permalink
method nostr.diconnect added
Browse files Browse the repository at this point in the history
  • Loading branch information
retog committed Jan 4, 2023
1 parent 0d1b792 commit 2a603c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const feeds = await nostr.globalFeed({
});
console.log('Feeds', feeds);

await nostr.disconnect();
console.log('Finish');
```

Expand Down
4 changes: 4 additions & 0 deletions lib/nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class Nostr extends EventEmitter {
return await this.getProfile(publicKey);
}

disconnect() {
return Promise.all(this.relayInstances.map(relay => relay.disconnect()));
}

private async getProfile(publicKey: string): Promise<ProfileInfo> {
const filters = {
kinds: [NostrKind.META_DATA],
Expand Down
5 changes: 4 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ class Relay {
}
async disconnect() {
this.manualClose = true;
await this.ws?.close(0);
await this.ws?.close(1000);
}
sendErrorEvent(err) {
this.nostr.emit('relayError', err, this);
Expand Down Expand Up @@ -27525,6 +27525,9 @@ class Nostr extends EventEmitter {
async getOtherProfile(publicKey) {
return await this.getProfile(publicKey);
}
disconnect() {
return Promise.all(this.relayInstances.map((relay)=>relay.disconnect()));
}
async getProfile(publicKey) {
const filters = {
kinds: [
Expand Down

0 comments on commit 2a603c0

Please sign in to comment.