Add support for to-device messages via OLM

This commit is contained in:
Robert Long 2022-04-26 15:20:06 -07:00
parent c05b6c5118
commit a0e4de73cc
5 changed files with 56 additions and 0 deletions

View file

@ -34,6 +34,7 @@
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#robertlong/group-call",
"mermaid": "^8.13.8",
"normalize.css": "^8.0.1",
"olm": "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz",
"pako": "^2.0.4",
"postcss-preset-env": "^6.7.0",
"re-resizable": "^6.9.0",

View file

@ -15,6 +15,7 @@
<body>
<div id="root"></div>
<script src="/node_modules/olm/olm.js"></script>
</body>
</html>

5
src/IndexedDBWorker.js Normal file
View file

@ -0,0 +1,5 @@
import { IndexedDBStoreWorker } from "matrix-js-sdk/src/indexeddb-worker";
const remoteWorker = new IndexedDBStoreWorker(self.postMessage);
self.onmessage = remoteWorker.onMessage;

View file

@ -3,6 +3,7 @@ import {
GroupCallIntent,
GroupCallType,
} from "matrix-js-sdk/src/browser-index";
import IndexedDBWorker from "./IndexedDBWorker?worker";
export const defaultHomeserver =
import.meta.env.VITE_DEFAULT_HOMESERVER ||
@ -26,11 +27,55 @@ function waitForSync(client) {
}
export async function initClient(clientOptions) {
let indexedDB;
try {
indexedDB = window.indexedDB;
} catch (e) {}
const storeOpts = {};
if (indexedDB && localStorage && !import.meta.env.DEV) {
storeOpts.store = new matrix.IndexedDBStore({
indexedDB: window.indexedDB,
localStorage: window.localStorage,
dbName: "element-call-sync",
workerFactory: () => new IndexedDBWorker(),
});
}
if (localStorage) {
storeOpts.sessionStore = new matrix.WebStorageSessionStore(localStorage);
}
if (indexedDB) {
storeOpts.cryptoStore = new matrix.IndexedDBCryptoStore(
indexedDB,
"matrix-js-sdk:crypto"
);
}
const client = matrix.createClient({
...storeOpts,
...clientOptions,
useAuthorizationHeader: true,
});
try {
await client.store.startup();
} catch (error) {
console.error(
"Error starting matrix client store. Falling back to memory store.",
error
);
client.store = new matrix.MemoryStore({ localStorage });
await client.store.startup();
}
if (client.initCrypto) {
await client.initCrypto();
}
await client.startClient({
// dirty hack to reduce chance of gappy syncs
// should be fixed by spotting gaps and backpaginating

View file

@ -8631,6 +8631,10 @@ objectorarray@^1.0.5:
resolved "https://registry.yarnpkg.com/objectorarray/-/objectorarray-1.0.5.tgz#2c05248bbefabd8f43ad13b41085951aac5e68a5"
integrity sha512-eJJDYkhJFFbBBAxeh8xW+weHlkI28n2ZdQV/J/DNfWfSKlGEf2xcfAbZTv3riEXHAhL9SVOTs2pRmXiSTf78xg==
"olm@https://packages.matrix.org/npm/olm/olm-3.2.1.tgz":
version "3.2.1"
resolved "https://packages.matrix.org/npm/olm/olm-3.2.1.tgz#d623d76f99c3518dde68be8c86618d68bc7b004a"
on-finished@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"