From 9238961992fa1dd5af91cef959b98ea967c139ad Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Dec 2021 17:19:10 +0100 Subject: [PATCH] cache olm and olm worker promise inside Platform as prep to call them every time a Client is created --- src/platform/web/Platform.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/platform/web/Platform.js b/src/platform/web/Platform.js index 4f0446ce..7c73e66f 100644 --- a/src/platform/web/Platform.js +++ b/src/platform/web/Platform.js @@ -157,6 +157,8 @@ export class Platform { const isIOS = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1) && !window.MSStream; this.isIOS = isIOS; this._disposables = new Disposables(); + this._olmPromise = undefined; + this._workerPromise = undefined; } _createLogger(isDevelopment) { @@ -179,7 +181,10 @@ export class Platform { } loadOlm() { - return loadOlm(this._config.olm); + if (!this._olmPromise) { + this._olmPromise = loadOlm(this._config.olm); + } + return this._olmPromise; } get config() { @@ -188,7 +193,10 @@ export class Platform { async loadOlmWorker() { if (!window.WebAssembly) { - return await loadOlmWorker(this._config); + if (!this._workerPromise) { + this._workerPromise = loadOlmWorker(this._config); + } + return this._workerPromise; } }