*Update dist
This commit is contained in:
parent
018c9f0387
commit
188fa6433b
|
@ -1 +1 @@
|
|||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAQA,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAS,QAAQ,EAAC,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAe9B,qBAAa,GAAG;IACC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ/C,KAAK,IAAI,OAAO,CAAC,QAAQ,CAAC;IAInB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5C;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,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;CAIrB"}
|
||||
{"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,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;CAIrB"}
|
|
@ -1,18 +1,24 @@
|
|||
import { callModule as callModuleKernel, connectModule as connectModuleKernel, } from "libkernel";
|
||||
import { callModule as callModuleModule, connectModule as connectModuleModule, } from "libkmodule";
|
||||
import { EventEmitter } from "events";
|
||||
const DHT_MODULE = "AQD1IgE4lTZkq1fqdoYGojKRNrSk0YQ_wrHbRtIiHDrnow";
|
||||
let callModule, connectModule;
|
||||
if (typeof window !== "undefined" && window?.document) {
|
||||
callModule = callModuleKernel;
|
||||
connectModule = connectModuleKernel;
|
||||
}
|
||||
else {
|
||||
callModule = callModuleModule;
|
||||
connectModule = connectModuleModule;
|
||||
async function loadLibs() {
|
||||
if (callModule && connectModule) {
|
||||
return;
|
||||
}
|
||||
if (typeof window !== "undefined" && window?.document) {
|
||||
const pkg = (await import("libkernel"));
|
||||
callModule = pkg.callModule;
|
||||
connectModule = pkg.connectModule;
|
||||
}
|
||||
else {
|
||||
const pkg = (await import("libkmodule"));
|
||||
callModule = pkg.callModule;
|
||||
connectModule = pkg.connectModule;
|
||||
}
|
||||
}
|
||||
export class DHT {
|
||||
async connect(pubkey) {
|
||||
await loadLibs();
|
||||
const [resp, err] = await callModule(DHT_MODULE, "connect", { pubkey });
|
||||
if (err) {
|
||||
throw new Error(err);
|
||||
|
@ -20,21 +26,25 @@ export class DHT {
|
|||
return new Socket(resp.id);
|
||||
}
|
||||
async ready() {
|
||||
await loadLibs();
|
||||
return callModule(DHT_MODULE, "ready");
|
||||
}
|
||||
async addRelay(pubkey) {
|
||||
await loadLibs();
|
||||
const [, err] = await callModule(DHT_MODULE, "addRelay", { pubkey });
|
||||
if (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
async removeRelay(pubkey) {
|
||||
await loadLibs();
|
||||
const [, err] = await callModule(DHT_MODULE, "removeRelay", { pubkey });
|
||||
if (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
}
|
||||
async clearRelays() {
|
||||
await loadLibs();
|
||||
await callModule(DHT_MODULE, "clearRelays");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue