*Dynamically load libraries
This commit is contained in:
parent
d3be614120
commit
25cefe8485
33
src/index.ts
33
src/index.ts
|
@ -1,26 +1,25 @@
|
||||||
import {
|
|
||||||
callModule as callModuleKernel,
|
|
||||||
connectModule as connectModuleKernel,
|
|
||||||
} from "libkernel";
|
|
||||||
import {
|
|
||||||
callModule as callModuleModule,
|
|
||||||
connectModule as connectModuleModule,
|
|
||||||
} from "libkmodule";
|
|
||||||
|
|
||||||
const DNS_MODULE = "AQBLKpieqOfKVRgMa8k45P4S_ILYgJmswVso4vT1qzoG-A";
|
const DNS_MODULE = "AQBLKpieqOfKVRgMa8k45P4S_ILYgJmswVso4vT1qzoG-A";
|
||||||
|
|
||||||
let callModule: typeof callModuleModule,
|
let callModule: any,
|
||||||
connectModule: typeof connectModuleModule;
|
connectModule: any;
|
||||||
|
|
||||||
if (window.document) {
|
async function loadLibs() {
|
||||||
callModule = callModuleKernel;
|
if (callModule && connectModule) {
|
||||||
connectModule = connectModuleKernel;
|
return;
|
||||||
} else {
|
}
|
||||||
callModule = callModuleModule;
|
if (typeof window !== "undefined" && window?.document) {
|
||||||
connectModule = connectModuleModule;
|
const pkg = (await import("libkernel"));
|
||||||
|
callModule = pkg.callModule;
|
||||||
|
connectModule = pkg.connectModule;
|
||||||
|
} else {
|
||||||
|
const pkg = (await import("libkmodule"));
|
||||||
|
callModule = pkg.callModule;
|
||||||
|
connectModule = pkg.connectModule;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resolve(domain: string, params: any, force = false) {
|
export async function resolve(domain: string, params: any, force = false) {
|
||||||
|
await loadLibs();
|
||||||
const [resp, err] = await callModule(DNS_MODULE, "resolve", {domain, params, force});
|
const [resp, err] = await callModule(DNS_MODULE, "resolve", {domain, params, force});
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
Loading…
Reference in New Issue