From e2aee0be819669ff4bf08313fcaac506eeed42c7 Mon Sep 17 00:00:00 2001 From: Robert Long Date: Tue, 26 Apr 2022 16:28:21 -0700 Subject: [PATCH] Fix olm import --- src/matrix-utils.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/matrix-utils.js b/src/matrix-utils.js index b1201f9..a5a0683 100644 --- a/src/matrix-utils.js +++ b/src/matrix-utils.js @@ -4,6 +4,8 @@ import { GroupCallType, } from "matrix-js-sdk/src/browser-index"; import IndexedDBWorker from "./IndexedDBWorker?worker"; +import olmJsPath from "olm/olm.js?url"; +import olmWasmPath from "olm/olm.wasm?url"; export const defaultHomeserver = 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) { + await addScript(olmJsPath); + await window.Olm.init({ locateFile: () => olmWasmPath }); + let indexedDB; try {