Fix olm import

This commit is contained in:
Robert Long 2022-04-26 16:28:21 -07:00
parent 44486aa62d
commit e2aee0be81

View file

@ -4,6 +4,8 @@ import {
GroupCallType, GroupCallType,
} from "matrix-js-sdk/src/browser-index"; } from "matrix-js-sdk/src/browser-index";
import IndexedDBWorker from "./IndexedDBWorker?worker"; import IndexedDBWorker from "./IndexedDBWorker?worker";
import olmJsPath from "olm/olm.js?url";
import olmWasmPath from "olm/olm.wasm?url";
export const defaultHomeserver = export const defaultHomeserver =
import.meta.env.VITE_DEFAULT_HOMESERVER || import.meta.env.VITE_DEFAULT_HOMESERVER ||
@ -26,7 +28,20 @@ function waitForSync(client) {
}); });
} }
function addScript(src) {
return new Promise((resolve, reject) => {
const script = document.createElement("script");
script.setAttribute("src", src);
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
}
export async function initClient(clientOptions) { export async function initClient(clientOptions) {
await addScript(olmJsPath);
await window.Olm.init({ locateFile: () => olmWasmPath });
let indexedDB; let indexedDB;
try { try {