Use webpack worker-loader to load the IndexedDB worker instead of homegrown hack
This commit is contained in:
parent
33dca81352
commit
d737b4e6ab
5 changed files with 47 additions and 21 deletions
23
src/@types/worker-loader.d.ts
vendored
Normal file
23
src/@types/worker-loader.d.ts
vendored
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare module "*.worker.ts" {
|
||||||
|
class WebpackWorker extends Worker {
|
||||||
|
constructor();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default WebpackWorker;
|
||||||
|
}
|
|
@ -50,15 +50,6 @@ export interface IMatrixClientCreds {
|
||||||
export interface IMatrixClientPeg {
|
export interface IMatrixClientPeg {
|
||||||
opts: IStartClientOpts;
|
opts: IStartClientOpts;
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the script href passed to the IndexedDB web worker
|
|
||||||
* If set, a separate web worker will be started to run the IndexedDB
|
|
||||||
* queries on.
|
|
||||||
*
|
|
||||||
* @param {string} script href to the script to be passed to the web worker
|
|
||||||
*/
|
|
||||||
setIndexedDbWorkerScript(script: string): void;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the server name of the user's homeserver
|
* Return the server name of the user's homeserver
|
||||||
* Throws an error if unable to deduce the homeserver name
|
* Throws an error if unable to deduce the homeserver name
|
||||||
|
@ -133,10 +124,6 @@ class _MatrixClientPeg implements IMatrixClientPeg {
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public setIndexedDbWorkerScript(script: string): void {
|
|
||||||
createMatrixClient.indexedDbWorkerScript = script;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get(): MatrixClient {
|
public get(): MatrixClient {
|
||||||
return this.matrixClient;
|
return this.matrixClient;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ import SettingsStore from "../../../settings/SettingsStore";
|
||||||
import { UIFeature } from "../../../settings/UIFeature";
|
import { UIFeature } from "../../../settings/UIFeature";
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
import BaseDialog from "./BaseDialog";
|
import BaseDialog from "./BaseDialog";
|
||||||
import GenericTextContextMenu from "../context_menus/GenericTextContextMenu.js";
|
import GenericTextContextMenu from "../context_menus/GenericTextContextMenu";
|
||||||
|
|
||||||
const socials = [
|
const socials = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import IndexedDBWorker from "../workers/indexeddb.worker.ts"; // `.ts` is needed here to make TS happy
|
||||||
import { createClient, ICreateClientOpts } from "matrix-js-sdk/src/matrix";
|
import { createClient, ICreateClientOpts } from "matrix-js-sdk/src/matrix";
|
||||||
import { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
|
import { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
|
||||||
import { WebStorageSessionStore } from "matrix-js-sdk/src/store/session/webstorage";
|
import { WebStorageSessionStore } from "matrix-js-sdk/src/store/session/webstorage";
|
||||||
|
@ -35,10 +36,6 @@ try {
|
||||||
* @param {Object} opts options to pass to Matrix.createClient. This will be
|
* @param {Object} opts options to pass to Matrix.createClient. This will be
|
||||||
* extended with `sessionStore` and `store` members.
|
* extended with `sessionStore` and `store` members.
|
||||||
*
|
*
|
||||||
* @property {string} indexedDbWorkerScript Optional URL for a web worker script
|
|
||||||
* for IndexedDB store operations. By default, indexeddb ops are done on
|
|
||||||
* the main thread.
|
|
||||||
*
|
|
||||||
* @returns {MatrixClient} the newly-created MatrixClient
|
* @returns {MatrixClient} the newly-created MatrixClient
|
||||||
*/
|
*/
|
||||||
export default function createMatrixClient(opts: ICreateClientOpts) {
|
export default function createMatrixClient(opts: ICreateClientOpts) {
|
||||||
|
@ -51,7 +48,7 @@ export default function createMatrixClient(opts: ICreateClientOpts) {
|
||||||
indexedDB: indexedDB,
|
indexedDB: indexedDB,
|
||||||
dbName: "riot-web-sync",
|
dbName: "riot-web-sync",
|
||||||
localStorage: localStorage,
|
localStorage: localStorage,
|
||||||
workerScript: createMatrixClient.indexedDbWorkerScript,
|
workerFactory: () => new IndexedDBWorker(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,5 +67,3 @@ export default function createMatrixClient(opts: ICreateClientOpts) {
|
||||||
...opts,
|
...opts,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createMatrixClient.indexedDbWorkerScript = null;
|
|
||||||
|
|
21
src/workers/indexeddb.worker.ts
Normal file
21
src/workers/indexeddb.worker.ts
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
Copyright 2017 Vector Creations 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { IndexedDBStoreWorker } from "matrix-js-sdk/src/indexeddb-worker";
|
||||||
|
|
||||||
|
const remoteWorker = new IndexedDBStoreWorker(postMessage as InstanceType<typeof Worker>["postMessage"]);
|
||||||
|
|
||||||
|
global.onmessage = remoteWorker.onMessage;
|
Loading…
Add table
Add a link
Reference in a new issue