*Update dist
This commit is contained in:
parent
85fb05b854
commit
ddf79c2efd
|
@ -14,6 +14,7 @@ export declare class DHT {
|
||||||
clearRelays(): Promise<void>;
|
clearRelays(): Promise<void>;
|
||||||
private create;
|
private create;
|
||||||
close(): Promise<boolean>;
|
close(): Promise<boolean>;
|
||||||
|
private setup;
|
||||||
}
|
}
|
||||||
export declare class Socket extends EventEmitter {
|
export declare class Socket extends EventEmitter {
|
||||||
private id;
|
private id;
|
||||||
|
|
|
@ -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,CA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G,MAAM,GAAG,IAAI;IAIrC,GAAG,IAAI,IAAI;IAIX,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;CAInB"}
|
|
@ -1,5 +1,4 @@
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
import { create } from "domain";
|
|
||||||
const DHT_MODULE = "AQD1IgE4lTZkq1fqdoYGojKRNrSk0YQ_wrHbRtIiHDrnow";
|
const DHT_MODULE = "AQD1IgE4lTZkq1fqdoYGojKRNrSk0YQ_wrHbRtIiHDrnow";
|
||||||
let callModule, connectModule;
|
let callModule, connectModule;
|
||||||
async function loadLibs() {
|
async function loadLibs() {
|
||||||
|
@ -22,10 +21,9 @@ export class DHT {
|
||||||
id = 0;
|
id = 0;
|
||||||
constructor(useDefaultDht = true) {
|
constructor(useDefaultDht = true) {
|
||||||
this.useDefaultDht = useDefaultDht;
|
this.useDefaultDht = useDefaultDht;
|
||||||
return create();
|
|
||||||
}
|
}
|
||||||
async connect(pubkey) {
|
async connect(pubkey) {
|
||||||
await loadLibs();
|
await this.setup();
|
||||||
const [resp, err] = await callModule(DHT_MODULE, "connect", { pubkey });
|
const [resp, err] = await callModule(DHT_MODULE, "connect", { pubkey });
|
||||||
if (err) {
|
if (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
|
@ -33,12 +31,12 @@ export class DHT {
|
||||||
return new Socket(resp.id);
|
return new Socket(resp.id);
|
||||||
}
|
}
|
||||||
async ready() {
|
async ready() {
|
||||||
await loadLibs();
|
await this.setup();
|
||||||
const dht = !this.useDefaultDht ? this.id : undefined;
|
const dht = !this.useDefaultDht ? this.id : undefined;
|
||||||
return callModule(DHT_MODULE, "ready", { dht });
|
return callModule(DHT_MODULE, "ready", { dht });
|
||||||
}
|
}
|
||||||
async addRelay(pubkey) {
|
async addRelay(pubkey) {
|
||||||
await loadLibs();
|
await this.setup();
|
||||||
const dht = !this.useDefaultDht ? this.id : undefined;
|
const dht = !this.useDefaultDht ? this.id : undefined;
|
||||||
const [, err] = await callModule(DHT_MODULE, "addRelay", { pubkey, dht });
|
const [, err] = await callModule(DHT_MODULE, "addRelay", { pubkey, dht });
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -46,7 +44,7 @@ export class DHT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async removeRelay(pubkey) {
|
async removeRelay(pubkey) {
|
||||||
await loadLibs();
|
await this.setup();
|
||||||
const dht = !this.useDefaultDht ? this.id : undefined;
|
const dht = !this.useDefaultDht ? this.id : undefined;
|
||||||
const [, err] = await callModule(DHT_MODULE, "removeRelay", {
|
const [, err] = await callModule(DHT_MODULE, "removeRelay", {
|
||||||
pubkey,
|
pubkey,
|
||||||
|
@ -57,13 +55,13 @@ export class DHT {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async clearRelays() {
|
async clearRelays() {
|
||||||
await loadLibs();
|
await this.setup();
|
||||||
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 });
|
||||||
}
|
}
|
||||||
async create() {
|
async create() {
|
||||||
await loadLibs();
|
await loadLibs();
|
||||||
if (this.useDefaultDht) {
|
if (this.useDefaultDht || this.id > 0) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
const [dht, err] = await callModule(DHT_MODULE, "openDht");
|
const [dht, err] = await callModule(DHT_MODULE, "openDht");
|
||||||
|
@ -73,7 +71,7 @@ export class DHT {
|
||||||
this.id = dht;
|
this.id = dht;
|
||||||
}
|
}
|
||||||
async close() {
|
async close() {
|
||||||
await loadLibs();
|
await this.setup();
|
||||||
if (this.useDefaultDht) {
|
if (this.useDefaultDht) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +81,10 @@ export class DHT {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
async setup() {
|
||||||
|
await loadLibs();
|
||||||
|
await this.create();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export class Socket extends EventEmitter {
|
export class Socket extends EventEmitter {
|
||||||
id;
|
id;
|
||||||
|
|
Loading…
Reference in New Issue