Skip to content

Commit 42e317d

Browse files
authored
Merge pull request element-hq#3578 from vector-im/dbkr/indexeddb_webworker
Add support for indexeddb sync in webworker
2 parents 4d4da0d + ec87003 commit 42e317d

4 files changed

Lines changed: 39 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 (_.endsWith(htmlWebpackPlugin.files.js[i], '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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
import {IndexedDBStoreWorker} from 'matrix-js-sdk/lib/indexeddb-worker.js';
18+
19+
const remoteWorker = new IndexedDBStoreWorker(postMessage);
20+
21+
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)