*Update dist
This commit is contained in:
parent
20c55f94ad
commit
cc3b188d5d
|
@ -4,11 +4,16 @@ import { EventEmitter } from "events";
|
||||||
import { ErrTuple } from "libskynet";
|
import { ErrTuple } from "libskynet";
|
||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
export declare class DHT {
|
export declare class DHT {
|
||||||
|
private useDefaultDht;
|
||||||
|
private id;
|
||||||
|
constructor(useDefaultDht?: boolean);
|
||||||
connect(pubkey: string): Promise<Socket>;
|
connect(pubkey: string): Promise<Socket>;
|
||||||
ready(): Promise<ErrTuple>;
|
ready(): Promise<ErrTuple>;
|
||||||
addRelay(pubkey: string): Promise<void>;
|
addRelay(pubkey: string): Promise<void>;
|
||||||
removeRelay(pubkey: string): Promise<void>;
|
removeRelay(pubkey: string): Promise<void>;
|
||||||
clearRelays(): Promise<void>;
|
clearRelays(): Promise<void>;
|
||||||
|
private create;
|
||||||
|
close(): Promise<boolean>;
|
||||||
}
|
}
|
||||||
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,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;CAI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AAE,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,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAStC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,GAAG,IAAI,IAAI;IAIX,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;CAInB"}
|
|
@ -6,17 +6,22 @@ async function loadLibs() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof window !== "undefined" && window?.document) {
|
if (typeof window !== "undefined" && window?.document) {
|
||||||
const pkg = (await import("libkernel"));
|
const pkg = await import("libkernel");
|
||||||
callModule = pkg.callModule;
|
callModule = pkg.callModule;
|
||||||
connectModule = pkg.connectModule;
|
connectModule = pkg.connectModule;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const pkg = (await import("libkmodule"));
|
const pkg = await import("libkmodule");
|
||||||
callModule = pkg.callModule;
|
callModule = pkg.callModule;
|
||||||
connectModule = pkg.connectModule;
|
connectModule = pkg.connectModule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export class DHT {
|
export class DHT {
|
||||||
|
useDefaultDht;
|
||||||
|
id;
|
||||||
|
constructor(useDefaultDht = true) {
|
||||||
|
this.useDefaultDht = useDefaultDht;
|
||||||
|
}
|
||||||
async connect(pubkey) {
|
async connect(pubkey) {
|
||||||
await loadLibs();
|
await loadLibs();
|
||||||
const [resp, err] = await callModule(DHT_MODULE, "connect", { pubkey });
|
const [resp, err] = await callModule(DHT_MODULE, "connect", { pubkey });
|
||||||
|
@ -27,25 +32,54 @@ export class DHT {
|
||||||
}
|
}
|
||||||
async ready() {
|
async ready() {
|
||||||
await loadLibs();
|
await loadLibs();
|
||||||
return callModule(DHT_MODULE, "ready");
|
const dht = !this.useDefaultDht ? this.id : undefined;
|
||||||
|
return callModule(DHT_MODULE, "ready", { dht });
|
||||||
}
|
}
|
||||||
async addRelay(pubkey) {
|
async addRelay(pubkey) {
|
||||||
await loadLibs();
|
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) {
|
if (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async removeRelay(pubkey) {
|
async removeRelay(pubkey) {
|
||||||
await loadLibs();
|
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) {
|
if (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async clearRelays() {
|
async clearRelays() {
|
||||||
await loadLibs();
|
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 {
|
export class Socket extends EventEmitter {
|
||||||
|
|
Loading…
Reference in New Issue