diff --git a/src/vector/app.js b/src/vector/app.js
index c77049f5..10ae1b39 100644
--- a/src/vector/app.js
+++ b/src/vector/app.js
@@ -170,6 +170,20 @@ export async function loadApp() {
throw new Error("Missing indexeddb worker script!");
}
MatrixClientPeg.setIndexedDbWorkerScript(window.vector_indexeddb_worker_script);
+
+ // load dendrite, if available
+ if (window.vector_dendrite_worker_script && 'serviceWorker' in navigator) {
+ window.addEventListener('load', ()=>{
+ navigator.serviceWorker.register(window.vector_dendrite_worker_script).then(function(registration) {
+ // Registration was successful
+ console.log('ServiceWorker registration successful with scope: ', registration.scope)
+ }, (err)=>{
+ // registration failed :(
+ console.log('ServiceWorker registration failed: ', err)
+ })
+ })
+ }
+
CallHandler.setConferenceHandler(VectorConferenceHandler);
window.addEventListener('hashchange', onHashChange);
diff --git a/src/vector/dendrite-sw.js b/src/vector/dendrite-sw.js
index 45639a7a..03720bab 100644
--- a/src/vector/dendrite-sw.js
+++ b/src/vector/dendrite-sw.js
@@ -14,7 +14,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-self.importScripts("wasm_exec.js", "bundles/go_http_bridge.js", "bundles/sqlite_bridge.js")
+const bundle_path = self.location.href.replace("/dendrite_sw.js", "")
+
+self.importScripts(`${bundle_path}/wasm_exec.js`,
+ `${bundle_path}/go_http_bridge.js`,
+ `${bundle_path}/sqlite_bridge.js`)
self.addEventListener('install', function(event) {
console.log("installing SW")
@@ -24,13 +28,13 @@ self.addEventListener('activate', function(event) {
console.log("SW activated")
const config = {
- locateFile: filename => 'sql_wasm.wasm'
+ locateFile: filename => `${bundle_path}/../../sql-wasm.wasm`
}
event.waitUntil(
sqlite_bridge.init(config).then(()=>{
const go = new Go()
- WebAssembly.instantiateStreaming(fetch('dendrite.wasm'), go.importObject).then((result) => {
+ WebAssembly.instantiateStreaming(fetch(`${bundle_path}/../../dendrite.wasm`), go.importObject).then((result) => {
go.run(result.instance)
});
})
diff --git a/src/vector/index.html b/src/vector/index.html
index a0ad91fc..2faca2f4 100644
--- a/src/vector/index.html
+++ b/src/vector/index.html
@@ -38,14 +38,15 @@
diff --git a/src/vector/wasm_exec.js b/src/vector/wasm_exec.js
index a54bb9a9..04a5d519 100644
--- a/src/vector/wasm_exec.js
+++ b/src/vector/wasm_exec.js
@@ -27,7 +27,10 @@
}
if (!global.fs && global.require) {
- global.fs = require("fs");
+ // XXX: require("fs") apparently returns {} in vector-web for webpack reasons
+ // so remove this so the polyfill below kicks in.
+ //
+ //global.fs = require("fs");
}
if (!global.fs) {
diff --git a/webpack.config.js b/webpack.config.js
index 34cb783f..78681217 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -32,13 +32,14 @@ module.exports = (env, argv) => {
entry: {
"bundle": "./src/vector/index.js",
- "indexeddb-worker": "./src/vector/indexeddb-worker.js",
- "dendrite-sw": "./src/vector/dendrite-sw.js",
+ "indexeddb_worker": "./src/vector/indexeddb-worker.js",
+ "dendrite_sw": "./src/vector/dendrite-sw.js",
"mobileguide": "./src/vector/mobile_guide/index.js",
"sqlite_bridge": "./node_modules/go-sqlite3-js/js/bridge.js",
"go_http_bridge": "./node_modules/go-http-js-libp2p/js/bridge.js",
"sql_wasm": "./node_modules/go-sqlite3-js/node_modules/sql.js/dist/sql-wasm.wasm",
"dendrite_wasm": "./src/vector/dendrite.wasm",
+ "wasm_exec": "./src/vector/wasm_exec.js",
// CSS themes
"theme-light": "./node_modules/matrix-react-sdk/res/themes/light/css/light.scss",
@@ -232,8 +233,8 @@ module.exports = (env, argv) => {
loader: "file-loader",
type: "javascript/auto", // https://github.com/webpack/webpack/issues/6725
options: {
- // fixme - we should have a hash in this for cachebusting, but haven't figured
- // out a way yet to pass the resulting path from webpack into dendrite-sw
+ // fixme: reintroduce [hash] once we can figure out how to pass it into the
+ // dendrite service worker nicely
name: '[name].[ext]',
outputPath: '.',
},