diff --git a/scripts/copy-res.js b/scripts/copy-res.js index 43b7768864..dc55cb1ad8 100755 --- a/scripts/copy-res.js +++ b/scripts/copy-res.js @@ -60,7 +60,7 @@ const COPY_LIST = [ // XXX: This is tied quite heavily to the matching olm.js so it really should be // in the bundle dir with the js to avoid caching issues giving us wasm that // doesn't match our js, but I cannot find any way to get webpack to do this. - ["node_modules/olm/olm.wasm", "webapp"], + ["node_modules/olm/olm.wasm", "webapp", { directwatch: 1 }], ["./config.json", "webapp", { directwatch: 1 }], ]; diff --git a/src/vector/index.js b/src/vector/index.js index ff6b12856c..e9452f65de 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -54,6 +54,8 @@ import SettingsStore, {SettingLevel} from "matrix-react-sdk/lib/settings/Setting import Tinter from 'matrix-react-sdk/lib/Tinter'; import SdkConfig from "matrix-react-sdk/lib/SdkConfig"; +import Olm from 'olm'; + import rageshake from "matrix-react-sdk/lib/rageshake/rageshake"; import CallHandler from 'matrix-react-sdk/lib/CallHandler'; @@ -227,6 +229,20 @@ async function loadApp() { window.addEventListener('hashchange', onHashChange); + /* Start loading Olm. Note that we *don't* wait for this to load: the + * js-sdk will also call this and actually wait on the promise before it + * tries to use the library. It can be loading its wasm while the rest of + * the app loads though. + * + * We also need to tell the Olm js to look for its wasm file at the same + * level as index.html. It really should be in the same place as the js, + * ie. in the bundle directory, to avoid caching issues, but as far as I + * can tell this is completely impossible with webpack. + */ + Olm.init({ + locateFile: () => 'olm.wasm', + }); + await loadLanguage(); const fragparts = parseQsFromFragment(window.location); diff --git a/src/vector/olm-loader.js b/src/vector/olm-loader.js deleted file mode 100644 index 29c83653a4..0000000000 --- a/src/vector/olm-loader.js +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2016 OpenMarket Ltd -Copyright 2018 New Vector Ltd - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -import olm from 'olm/olm.js'; - -/* a very thin shim for loading olm.js: just sets the global OLM_OPTIONS and - * requires the actual olm.js library. - * - * olm.js reads global.OLM_OPTIONS and defines global.Olm. The latter is fine for us, - * but we need to prepare the former. - * - * We can't use webpack's definePlugin to do this, because we tell webpack not - * to parse olm.js. We also can't put this code in index.js, because olm and - * index.js are loaded in parallel, and we need to make sure OLM_OPTIONS is set - * before olm.js is loaded. - */ - -/* Tell the Olm js to look for its wasm file at the same level as index.html. - * It really should be in the same place as the js, ie. in the bundle directory, - * to avoid caching issues, but as far as I can tell this is completely impossible - * with webpack. - */ -global.OLM_OPTIONS = { - locateFile: () => 'olm.wasm', -}; diff --git a/webpack.config.js b/webpack.config.js index 122facb24b..e8f20d29b7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -15,15 +15,6 @@ module.exports = { "mobileguide": "./src/vector/mobile_guide/index.js", - // We ship olm.js as a separate lump of javascript. This makes it get - // loaded via a separate