From f404dff8ebc5cbe24e98805889ef7f039c8f3745 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 14 Aug 2022 07:32:37 -0400 Subject: [PATCH] *add getRelays and getRelayServers methods --- src/index.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7c0ea18..f598e5f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,6 +75,24 @@ export class DHT { const dht = !this.useDefaultDht ? this.id : undefined; await callModule(DHT_MODULE, "clearRelays", { dht }); } + public async getRelays(): Promise { + await this.setup(); + const [list, err] = await callModule(DHT_MODULE, "getRelays"); + if (err) { + throw new Error(err); + } + + return list; + } + public async getRelayServers(): Promise { + await this.setup(); + const [list, err] = await callModule(DHT_MODULE, "getRelayServers"); + if (err) { + throw new Error(err); + } + + return list; + } private async create() { await loadLibs(); @@ -150,11 +168,13 @@ export class Socket extends EventEmitter { } end(): void { - callModule(DHT_MODULE, "socketExists", { id: this.id }).then(([exists]: ErrTuple) => { - if (exists) { - callModule(DHT_MODULE, "close", { id: this.id }); + callModule(DHT_MODULE, "socketExists", { id: this.id }).then( + ([exists]: ErrTuple) => { + if (exists) { + callModule(DHT_MODULE, "close", { id: this.id }); + } } - }); + ); } private ensureEvent(event: string): void {