*Update dist

This commit is contained in:
Derrick Hammer 2022-08-03 12:29:53 -04:00
parent 20c55f94ad
commit cc3b188d5d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 46 additions and 7 deletions

5
dist/index.d.ts vendored
View File

@ -4,11 +4,16 @@ import { EventEmitter } from "events";
import { ErrTuple } from "libskynet";
import { Buffer } from "buffer";
export declare class DHT {
private useDefaultDht;
private id;
constructor(useDefaultDht?: boolean);
connect(pubkey: string): Promise<Socket>;
ready(): Promise<ErrTuple>;
addRelay(pubkey: string): Promise<void>;
removeRelay(pubkey: string): Promise<void>;
clearRelays(): Promise<void>;
private create;
close(): Promise<boolean>;
}
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,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAS,QAAQ,EAAC,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAsB9B,qBAAa,GAAG;IACC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS/C,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC;IAKnB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAI5C;AAED,qBAAa,MAAO,SAAQ,YAAY;IACpC,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,G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E,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,GAAG,IAAI,IAAI;IAIX,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;CAInB"}

46
dist/index.js vendored
View File

@ -6,17 +6,22 @@ async function loadLibs() {
return;
}
if (typeof window !== "undefined" && window?.document) {
const pkg = (await import("libkernel"));
const pkg = await import("libkernel");
callModule = pkg.callModule;
connectModule = pkg.connectModule;
}
else {
const pkg = (await import("libkmodule"));
const pkg = await import("libkmodule");
callModule = pkg.callModule;
connectModule = pkg.connectModule;
}
}
export class DHT {
useDefaultDht;
id;
constructor(useDefaultDht = true) {
this.useDefaultDht = useDefaultDht;
}
async connect(pubkey) {
await loadLibs();
const [resp, err] = await callModule(DHT_MODULE, "connect", { pubkey });
@ -27,25 +32,54 @@ export class DHT {
}
async ready() {
await loadLibs();
return callModule(DHT_MODULE, "ready");
const dht = !this.useDefaultDht ? this.id : undefined;
return callModule(DHT_MODULE, "ready", { dht });
}
async addRelay(pubkey) {
await loadLibs();
const [, err] = await callModule(DHT_MODULE, "addRelay", { pubkey });
const dht = !this.useDefaultDht ? this.id : undefined;
const [, err] = await callModule(DHT_MODULE, "addRelay", { pubkey, dht });
if (err) {
throw new Error(err);
}
}
async removeRelay(pubkey) {
await loadLibs();
const [, err] = await callModule(DHT_MODULE, "removeRelay", { pubkey });
const dht = !this.useDefaultDht ? this.id : undefined;
const [, err] = await callModule(DHT_MODULE, "removeRelay", {
pubkey,
dht,
});
if (err) {
throw new Error(err);
}
}
async clearRelays() {
await loadLibs();
await callModule(DHT_MODULE, "clearRelays");
const dht = !this.useDefaultDht ? this.id : undefined;
await callModule(DHT_MODULE, "clearRelays", { dht });
}
async create() {
await loadLibs();
if (this.useDefaultDht) {
return Promise.resolve();
}
const [dht, err] = await callModule(DHT_MODULE, "openDht");
if (err) {
throw new Error(err);
}
this.id = dht;
}
async close() {
await loadLibs();
if (this.useDefaultDht) {
return false;
}
const [, err] = await callModule(DHT_MODULE, "closeDht", { dht: this.id });
if (err) {
throw new Error(err);
}
return true;
}
}
export class Socket extends EventEmitter {