Skip to content

Commit f187a35

Browse files
committed
Add support for indexeddb sync in webworker
1 parent 579e70e commit f187a35

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎src/vector/index.html‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,19 @@
3737
<body style="height: 100%;">
3838
<section id="matrixchat" style="height: 100%;"></section>
3939
<noscript>Sorry, Riot requires JavaScript to be enabled.</noscript>
40-
<% for (var i=0; i < htmlWebpackPlugin.files.js.length; i++) {%>
41-
<script src="<%= htmlWebpackPlugin.files.js[i] %>"></script>
40+
<% for (var i=0; i < htmlWebpackPlugin.files.js.length; i++) {
41+
// Not a particularly graceful way of not putting the indexeddb worker script
42+
// into the main page
43+
if (htmlWebpackPlugin.files.js[i].endsWith('indexeddb-worker.js')) {
44+
%>
45+
<script>
46+
window.vector_indexeddb_worker_script = '<%= htmlWebpackPlugin.files.js[i] %>';
47+
</script>
48+
<%
49+
continue;
50+
}
51+
%>
52+
<script src="<%= htmlWebpackPlugin.files.js[i] %>"></script>
4253
<% } %>
4354
<img src="img/warning.svg" width="24" height="23" style="visibility: hidden; position: absolute; top: 0px; left: 0px;"/>
4455
<audio id="messageAudio">

‎src/vector/index.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ import url from 'url';
6868
import {parseQs, parseQsFromFragment} from './url_utils';
6969
import Platform from './platform';
7070

71+
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
72+
7173
var lastLocationHashSet = null;
7274

7375
var CallHandler = require("matrix-react-sdk/lib/CallHandler");
7476
CallHandler.setConferenceHandler(VectorConferenceHandler);
7577

78+
MatrixClientPeg.setIndexedDbWorkerScript(window.vector_indexeddb_worker_script);
79+
7680
function checkBrowserFeatures(featureList) {
7781
if (!window.Modernizr) {
7882
console.error("Cannot check features - Modernizr global is missing.");

‎src/vector/indexedbd-worker.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2017 Vector Creations Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// The prescribed way of doing this import would be:
18+
//import {IndexedDbStoreWorker} from 'matrix-js-sdk';
19+
// However, this still pulls in all of the js-sdk and we only use a tiny fraction
20+
// of it. It also causes an Olm error to appear because we don't have an Olm in scope.
21+
// Instead, we do this:
22+
import IndexedDbStoreWorker from 'matrix-js-sdk/lib/store/indexeddb-remote-worker';
23+
24+
const remoteWorker = new IndexedDbStoreWorker(postMessage);
25+
26+
onmessage = remoteWorker.onMessage;

‎webpack.config.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
66
module.exports = {
77
entry: {
88
"bundle": "./src/vector/index.js",
9+
"indexeddb-worker": "./src/vector/indexedbd-worker.js",
910

1011
// We ship olm.js as a separate lump of javascript. This makes it get
1112
// loaded via a separate <script/> tag in index.html (which loads it

0 commit comments

Comments
 (0)