From 2648bce78b8aa86c01eaa3c04b39921cc3423ce8 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Mon, 8 Jun 2026 12:21:48 +0200 Subject: [PATCH] fix(encryption): load wasm module on demand - Encryption.isSupported() have a side effect of initializing Olm module - Should be pre-checked if needed by Encryption.isEnabled() - Already done in src/utils/webrtc/index.js, but not in src/utils/signaling.js - Migrated to async syntax Signed-off-by: Maksim Sukharev --- src/utils/e2ee/encryption.js | 2 +- src/utils/signaling.js | 57 +++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/utils/e2ee/encryption.js b/src/utils/e2ee/encryption.js index 859047b64ef..535741c7012 100644 --- a/src/utils/e2ee/encryption.js +++ b/src/utils/e2ee/encryption.js @@ -39,7 +39,7 @@ class Encryption { /** * Check if the current browser supports encryption. * - * @return {boolean} Returns true if supported and throws an error otherwise. + * @return {Promise} Returns true if supported and throws an error otherwise. * @async */ static async isSupported() { diff --git a/src/utils/signaling.js b/src/utils/signaling.js index 3c6ac2f925c..62444c66c24 100644 --- a/src/utils/signaling.js +++ b/src/utils/signaling.js @@ -1003,7 +1003,7 @@ Signaling.Standalone.prototype._getBackendUrl = function(baseURL = undefined) { return generateOcsUrl('apps/spreed/api/v3/signaling/backend', {}, { baseURL }) } -Signaling.Standalone.prototype.sendHello = function() { +Signaling.Standalone.prototype.sendHello = async function() { if (this.resumeId) { console.debug('Trying to resume session', this.sessionId) const msg = { @@ -1027,33 +1027,36 @@ Signaling.Standalone.prototype.sendHello = function() { helloVersion = '1.0' } const features = ['chat-relay'] - Encryption.isSupported() - .then(() => { - features.push('encryption') - }) - .catch(() => { - // Ignore any errors. - }) - .finally(() => { - const msg = { - type: 'hello', - hello: { - version: helloVersion, - auth: { - url, - params: this.settings.helloAuthParams[helloVersion], - }, - }, - } - if (features.length > 0) { - msg.hello.features = features - } - if (this.settings.helloAuthParams.internal) { - msg.hello.auth.type = 'internal' - msg.hello.auth.params = this.settings.helloAuthParams.internal + + try { + if (Encryption.isEnabled()) { + const isSupported = await Encryption.isSupported() + if (isSupported) { + features.push('encryption') } - this.doSend(msg, this.helloResponseReceived.bind(this)) - }) + } + } catch (error) { + // Ignore any errors. + } + + const msg = { + type: 'hello', + hello: { + version: helloVersion, + auth: { + url, + params: this.settings.helloAuthParams[helloVersion], + }, + }, + } + if (features.length > 0) { + msg.hello.features = features + } + if (this.settings.helloAuthParams.internal) { + msg.hello.auth.type = 'internal' + msg.hello.auth.params = this.settings.helloAuthParams.internal + } + this.doSend(msg, this.helloResponseReceived.bind(this)) } Signaling.Standalone.prototype.helloResponseReceived = function(data) {