*add getRelays and getRelayServers methods
This commit is contained in:
parent
77141c3003
commit
f404dff8eb
28
src/index.ts
28
src/index.ts
|
@ -75,6 +75,24 @@ export class DHT {
|
||||||
const dht = !this.useDefaultDht ? this.id : undefined;
|
const dht = !this.useDefaultDht ? this.id : undefined;
|
||||||
await callModule(DHT_MODULE, "clearRelays", { dht });
|
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() {
|
private async create() {
|
||||||
await loadLibs();
|
await loadLibs();
|
||||||
|
@ -150,11 +168,13 @@ export class Socket extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
end(): void {
|
end(): void {
|
||||||
callModule(DHT_MODULE, "socketExists", { id: this.id }).then(([exists]: ErrTuple) => {
|
callModule(DHT_MODULE, "socketExists", { id: this.id }).then(
|
||||||
if (exists) {
|
([exists]: ErrTuple) => {
|
||||||
callModule(DHT_MODULE, "close", { id: this.id });
|
if (exists) {
|
||||||
|
callModule(DHT_MODULE, "close", { id: this.id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ensureEvent(event: string): void {
|
private ensureEvent(event: string): void {
|
||||||
|
|
Loading…
Reference in New Issue