Use webpack worker-loader to load the IndexedDB worker instead of homegrown hack

This commit is contained in:
Michael Telatynski 2021-07-12 18:43:20 +01:00
parent 33dca81352
commit d737b4e6ab
5 changed files with 47 additions and 21 deletions

View file

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
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 { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
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
* 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
*/
export default function createMatrixClient(opts: ICreateClientOpts) {
@ -51,7 +48,7 @@ export default function createMatrixClient(opts: ICreateClientOpts) {
indexedDB: indexedDB,
dbName: "riot-web-sync",
localStorage: localStorage,
workerScript: createMatrixClient.indexedDbWorkerScript,
workerFactory: () => new IndexedDBWorker(),
});
}
@ -70,5 +67,3 @@ export default function createMatrixClient(opts: ICreateClientOpts) {
...opts,
});
}
createMatrixClient.indexedDbWorkerScript = null;