*Update dist

This commit is contained in:
Derrick Hammer 2022-08-03 12:37:15 -04:00
parent 85fb05b854
commit ddf79c2efd
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 13 additions and 10 deletions

1
dist/index.d.ts vendored
View File

@ -14,6 +14,7 @@ export declare class DHT {
clearRelays(): Promise<void>;
private create;
close(): Promise<boolean>;
private setup;
}
export declare class Socket extends EventEmitter {
private id;

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAU,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAsBhC,qBAAa,GAAG;IACd,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,EAAE,CAAa;gBAEX,aAAa,UAAO;IAKnB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS/C,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC;IAMnB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASvC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;YAM3B,MAAM;IAaP,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC;CAavC;AAED,qBAAa,MAAO,SAAQ,YAAY;IACtC,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAqC;gBAE7C,EAAE,EAAE,MAAM;IAKtB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAkB/D,GAAG,CAAC,IAAI,EAAE,MAAM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IrC,GAAG,IAAI,IAAI;IAIX,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;CAInB"}

20
dist/index.js vendored
View File

@ -1,5 +1,4 @@
import { EventEmitter } from "events";
import { create } from "domain";
const DHT_MODULE = "AQD1IgE4lTZkq1fqdoYGojKRNrSk0YQ_wrHbRtIiHDrnow";
let callModule, connectModule;
async function loadLibs() {
@ -22,10 +21,9 @@ export class DHT {
id = 0;
constructor(useDefaultDht = true) {
this.useDefaultDht = useDefaultDht;
return create();
}
async connect(pubkey) {
await loadLibs();
await this.setup();
const [resp, err] = await callModule(DHT_MODULE, "connect", { pubkey });
if (err) {
throw new Error(err);
@ -33,12 +31,12 @@ export class DHT {
return new Socket(resp.id);
}
async ready() {
await loadLibs();
await this.setup();
const dht = !this.useDefaultDht ? this.id : undefined;
return callModule(DHT_MODULE, "ready", { dht });
}
async addRelay(pubkey) {
await loadLibs();
await this.setup();
const dht = !this.useDefaultDht ? this.id : undefined;
const [, err] = await callModule(DHT_MODULE, "addRelay", { pubkey, dht });
if (err) {
@ -46,7 +44,7 @@ export class DHT {
}
}
async removeRelay(pubkey) {
await loadLibs();
await this.setup();
const dht = !this.useDefaultDht ? this.id : undefined;
const [, err] = await callModule(DHT_MODULE, "removeRelay", {
pubkey,
@ -57,13 +55,13 @@ export class DHT {
}
}
async clearRelays() {
await loadLibs();
await this.setup();
const dht = !this.useDefaultDht ? this.id : undefined;
await callModule(DHT_MODULE, "clearRelays", { dht });
}
async create() {
await loadLibs();
if (this.useDefaultDht) {
if (this.useDefaultDht || this.id > 0) {
return Promise.resolve();
}
const [dht, err] = await callModule(DHT_MODULE, "openDht");
@ -73,7 +71,7 @@ export class DHT {
this.id = dht;
}
async close() {
await loadLibs();
await this.setup();
if (this.useDefaultDht) {
return false;
}
@ -83,6 +81,10 @@ export class DHT {
}
return true;
}
async setup() {
await loadLibs();
await this.create();
}
}
export class Socket extends EventEmitter {
id;