diff --git a/package.json b/package.json index 9c878557..d74822df 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,8 @@ "favico.js": "^0.3.10", "gemini-scrollbar": "github:matrix-org/gemini-scrollbar#91e1e566", "gfm.css": "^1.1.2", + "go-sqlite-js": "^0.1.0", + "go-http-js-libp2p": "^0.1.0", "highlight.js": "^9.13.1", "matrix-js-sdk": "3.0.0", "matrix-react-sdk": "1.7.6", diff --git a/src/vector/dendrite-sw.js b/src/vector/dendrite-sw.js new file mode 100644 index 00000000..45639a7a --- /dev/null +++ b/src/vector/dendrite-sw.js @@ -0,0 +1,53 @@ +// -*- coding: utf-8 -*- +// Copyright 2020 The Matrix.org Foundation C.I.C. +// Copyright 2020 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. + +self.importScripts("wasm_exec.js", "bundles/go_http_bridge.js", "bundles/sqlite_bridge.js") + +self.addEventListener('install', function(event) { + console.log("installing SW") +}) + +self.addEventListener('activate', function(event) { + console.log("SW activated") + + const config = { + locateFile: filename => 'sql_wasm.wasm' + } + + event.waitUntil( + sqlite_bridge.init(config).then(()=>{ + const go = new Go() + WebAssembly.instantiateStreaming(fetch('dendrite.wasm'), go.importObject).then((result) => { + go.run(result.instance) + }); + }) + ) +}) + +self.addEventListener('fetch', function(event) { + console.log("intercepted " + event.request.url) + if (event.request.url.match(/\/_matrix\/client/)) { + if (global.fetchListener) { + event.respondWith(global.fetchListener.onFetch(event)) + } + else { + console.log("no fetch listener present for " + event.request.url) + } + } + else { + return fetch(event.request) + } +}) diff --git a/src/vector/dendrite.wasm b/src/vector/dendrite.wasm new file mode 100755 index 00000000..75053c4b Binary files /dev/null and b/src/vector/dendrite.wasm differ diff --git a/src/vector/index.html b/src/vector/index.html index fc880633..a0ad91fc 100644 --- a/src/vector/index.html +++ b/src/vector/index.html @@ -39,6 +39,7 @@