diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js --- a/keyserver/src/responders/website-responders.js +++ b/keyserver/src/responders/website-responders.js @@ -63,7 +63,12 @@ } } -type AssetInfo = { jsURL: string, fontsURL: string, cssInclude: string }; +type AssetInfo = { + +jsURL: string, + +fontsURL: string, + +cssInclude: string, + +olmFilename: string, +}; let assetInfo: ?AssetInfo = null; async function getAssetInfo() { if (assetInfo) { @@ -75,6 +80,7 @@ jsURL: 'http://localhost:8080/dev.build.js', fontsURL, cssInclude: '', + olmFilename: '', }; return assetInfo; } @@ -91,6 +97,7 @@ href="compiled/${assets.browser.css}" /> `, + olmFilename: assets[''].wasm, }; return assetInfo; } catch { @@ -316,7 +323,7 @@ return pushConfig.publicKey; })(); - const { jsURL, fontsURL, cssInclude } = await assetInfoPromise; + const { jsURL, fontsURL, cssInclude, olmFilename } = await assetInfoPromise; // prettier-ignore res.write(html` @@ -413,6 +420,7 @@ res.end(html` ; var baseURL = "${baseURL}"; + var olmFilename = "${olmFilename}"; diff --git a/web/account/log-in-form.react.js b/web/account/log-in-form.react.js --- a/web/account/log-in-form.react.js +++ b/web/account/log-in-form.react.js @@ -12,6 +12,7 @@ import SIWELoginForm from './siwe-login-form.react.js'; import TraditionalLoginForm from './traditional-login-form.react.js'; import OrBreak from '../components/or-break.react.js'; +import { initOlm } from '../olm/olm-utils.js'; import { setPrimaryIdentityKeys, setNotificationIdentityKeys, @@ -42,7 +43,7 @@ ) { return; } - await olm.init(); + await initOlm(); const identityAccount = new olm.Account(); identityAccount.create(); diff --git a/web/olm/olm-utils.js b/web/olm/olm-utils.js new file mode 100644 --- /dev/null +++ b/web/olm/olm-utils.js @@ -0,0 +1,16 @@ +// @flow + +import olm from '@matrix-org/olm'; + +declare var olmFilename: string; + +async function initOlm(): Promise { + if (!olmFilename) { + return await olm.init(); + } + const locateFile = (wasmFilename: string, httpAssetsHost: string) => + httpAssetsHost + olmFilename; + return await olm.init({ locateFile }); +} + +export { initOlm }; diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs --- a/web/webpack.config.cjs +++ b/web/webpack.config.cjs @@ -12,16 +12,6 @@ const babelConfig = require('./babel.config.cjs'); const baseBrowserConfig = { - plugins: [ - new CopyPlugin({ - patterns: [ - { - from: 'node_modules/@matrix-org/olm/olm.wasm', - to: path.join(__dirname, 'dist'), - }, - ], - }), - ], entry: { browser: ['./script.js'], }, @@ -58,12 +48,30 @@ directory: path.join(__dirname, 'dist'), }, }, + plugins: [ + new CopyPlugin({ + patterns: [ + { + from: 'node_modules/@matrix-org/olm/olm.wasm', + to: path.join(__dirname, 'dist'), + }, + ], + }), + ], }; const baseProdBrowserConfig = { ...baseBrowserConfig, plugins: [ - ...baseBrowserConfig.plugins, + new CopyPlugin({ + patterns: [ + { + from: 'node_modules/@matrix-org/olm/olm.wasm', + to: path.join(__dirname, 'dist', 'olm.[contenthash:12].wasm'), + info: { chunk: 'test' }, + }, + ], + }), new AssetsPlugin({ filename: 'assets.json', path: path.join(__dirname, 'dist'),