From c511902356434b53f7e05617c7195871383e6897 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 25 Sep 2018 17:55:41 +0100 Subject: [PATCH] Support WebAssembly version of Olm. * Olm no longer supports setting the stack/memory size at runtime, so don't (they're now set to be that in the Olm build). * Copy the wasm file from the Olm library (see multiple comments about it being in the wrong place and webpack being awful). --- scripts/copy-res.js | 4 ++++ src/vector/olm-loader.js | 18 ++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/copy-res.js b/scripts/copy-res.js index 70a06411d9..43b7768864 100755 --- a/scripts/copy-res.js +++ b/scripts/copy-res.js @@ -57,6 +57,10 @@ const COPY_LIST = [ ["res/themes/**", "webapp/themes"], ["node_modules/emojione/assets/svg/*", "webapp/emojione/svg/"], ["node_modules/emojione/assets/png/*", "webapp/emojione/png/"], + // 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"], ["./config.json", "webapp", { directwatch: 1 }], ]; diff --git a/src/vector/olm-loader.js b/src/vector/olm-loader.js index a62d05b40e..29c83653a4 100644 --- a/src/vector/olm-loader.js +++ b/src/vector/olm-loader.js @@ -1,5 +1,6 @@ /* 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. @@ -14,6 +15,8 @@ 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. * @@ -26,16 +29,11 @@ limitations under the License. * before olm.js is loaded. */ -/* total_memory must be a power of two, and at least twice the stack. - * - * We don't need a lot of stack, but we do need about 128K of heap to encrypt a - * 64K event (enough to store the ciphertext and the plaintext, bearing in mind - * that the plaintext can only be 48K because base64). We also have about 36K - * of statics. So let's have 256K of memory. +/* 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 = { - TOTAL_STACK: 64*1024, - TOTAL_MEMORY: 256*1024, + locateFile: () => 'olm.wasm', }; - -require('olm/olm.js');