Merge pull request #303 from vector-im/to-device-olm2
Add support for to-device messages via OLM
This commit is contained in:
commit
6913fddcd3
3 changed files with 57 additions and 0 deletions
|
@ -13,6 +13,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@juggle/resize-observer": "^3.3.1",
|
"@juggle/resize-observer": "^3.3.1",
|
||||||
|
"@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.8.tgz",
|
||||||
"@react-aria/button": "^3.3.4",
|
"@react-aria/button": "^3.3.4",
|
||||||
"@react-aria/dialog": "^3.1.4",
|
"@react-aria/dialog": "^3.1.4",
|
||||||
"@react-aria/focus": "^3.5.0",
|
"@react-aria/focus": "^3.5.0",
|
||||||
|
|
5
src/IndexedDBWorker.js
Normal file
5
src/IndexedDBWorker.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { IndexedDBStoreWorker } from "matrix-js-sdk/src/indexeddb-worker";
|
||||||
|
|
||||||
|
const remoteWorker = new IndexedDBStoreWorker(self.postMessage);
|
||||||
|
|
||||||
|
self.onmessage = remoteWorker.onMessage;
|
|
@ -3,6 +3,9 @@ import {
|
||||||
GroupCallIntent,
|
GroupCallIntent,
|
||||||
GroupCallType,
|
GroupCallType,
|
||||||
} from "matrix-js-sdk/src/browser-index";
|
} from "matrix-js-sdk/src/browser-index";
|
||||||
|
import IndexedDBWorker from "./IndexedDBWorker?worker";
|
||||||
|
import Olm from "@matrix-org/olm";
|
||||||
|
import olmWasmPath from "@matrix-org/olm/olm.wasm?url";
|
||||||
|
|
||||||
export const defaultHomeserver =
|
export const defaultHomeserver =
|
||||||
import.meta.env.VITE_DEFAULT_HOMESERVER ||
|
import.meta.env.VITE_DEFAULT_HOMESERVER ||
|
||||||
|
@ -26,11 +29,59 @@ function waitForSync(client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initClient(clientOptions) {
|
export async function initClient(clientOptions) {
|
||||||
|
// TODO: https://gitlab.matrix.org/matrix-org/olm/-/issues/10
|
||||||
|
window.OLM_OPTIONS = {};
|
||||||
|
await Olm.init({ locateFile: () => olmWasmPath });
|
||||||
|
|
||||||
|
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({
|
const client = matrix.createClient({
|
||||||
|
...storeOpts,
|
||||||
...clientOptions,
|
...clientOptions,
|
||||||
useAuthorizationHeader: true,
|
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({
|
await client.startClient({
|
||||||
// dirty hack to reduce chance of gappy syncs
|
// dirty hack to reduce chance of gappy syncs
|
||||||
// should be fixed by spotting gaps and backpaginating
|
// should be fixed by spotting gaps and backpaginating
|
||||||
|
|
Loading…
Add table
Reference in a new issue