mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
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
@ -13,6 +13,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@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/dialog": "^3.1.4",
|
||||
"@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,
|
||||
GroupCallType,
|
||||
} 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 =
|
||||
import.meta.env.VITE_DEFAULT_HOMESERVER ||
|
||||
@ -26,11 +29,59 @@ function waitForSync(client) {
|
||||
}
|
||||
|
||||
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({
|
||||
...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
|
||||
|
Loading…
Reference in New Issue
Block a user