*add getRelays and getRelayServers methods

This commit is contained in:
Derrick Hammer 2022-08-14 07:32:37 -04:00
parent 77141c3003
commit f404dff8eb
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 24 additions and 4 deletions

View File

@ -75,6 +75,24 @@ export class DHT {
const dht = !this.useDefaultDht ? this.id : undefined;
await callModule(DHT_MODULE, "clearRelays", { dht });
}
public async getRelays(): Promise<string[]> {
await this.setup();
const [list, err] = await callModule(DHT_MODULE, "getRelays");
if (err) {
throw new Error(err);
}
return list;
}
public async getRelayServers(): Promise<string[]> {
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) => {
callModule(DHT_MODULE, "socketExists", { id: this.id }).then(
([exists]: ErrTuple) => {
if (exists) {
callModule(DHT_MODULE, "close", { id: this.id });
}
});
}
);
}
private ensureEvent(event: string): void {