xinny/src/client/initMatrix.js
Ajay Bura 989ab5a432
Add support to manage cross-signing and key backup (#461)
* Add useDeviceList hook

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add isCrossVerified func to matrixUtil

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add className prop in sidebar avatar comp

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add unverified session indicator in sidebar

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add info card component

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add css variables

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add cross signin status hook

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add hasCrossSigninAccountData function

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add cross signin info card in device manage component

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add cross signing and key backup component

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Fix typo

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* WIP

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add cross singing dialogs

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add cross signing set/reset

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add SecretStorageAccess component

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* Add key backup

Signed-off-by: Ajay Bura <ajbura@gmail.com>

* WIP

* WIP

* WIP

* WIP

* Show progress when restoring key backup

* Add SSSS and key backup
2022-04-24 15:42:24 +05:30

101 lines
2.8 KiB
JavaScript

import EventEmitter from 'events';
import * as sdk from 'matrix-js-sdk';
// import { logger } from 'matrix-js-sdk/lib/logger';
import { secret } from './state/auth';
import RoomList from './state/RoomList';
import AccountData from './state/AccountData';
import RoomsInput from './state/RoomsInput';
import Notifications from './state/Notifications';
import { cryptoCallbacks } from './state/secretStorageKeys';
global.Olm = require('@matrix-org/olm');
// logger.disableAll();
class InitMatrix extends EventEmitter {
async init() {
await this.startClient();
this.setupSync();
this.listenEvents();
}
async startClient() {
const indexedDBStore = new sdk.IndexedDBStore({
indexedDB: global.indexedDB,
localStorage: global.localStorage,
dbName: 'web-sync-store',
});
await indexedDBStore.startup();
this.matrixClient = sdk.createClient({
baseUrl: secret.baseUrl,
accessToken: secret.accessToken,
userId: secret.userId,
store: indexedDBStore,
sessionStore: new sdk.WebStorageSessionStore(global.localStorage),
cryptoStore: new sdk.IndexedDBCryptoStore(global.indexedDB, 'crypto-store'),
deviceId: secret.deviceId,
timelineSupport: true,
cryptoCallbacks,
});
await this.matrixClient.initCrypto();
await this.matrixClient.startClient({
lazyLoadMembers: true,
});
this.matrixClient.setGlobalErrorOnUnknownDevices(false);
}
setupSync() {
const sync = {
NULL: () => {
console.log('NULL state');
},
SYNCING: () => {
console.log('SYNCING state');
},
PREPARED: (prevState) => {
console.log('PREPARED state');
console.log('previous state: ', prevState);
// TODO: remove global.initMatrix at end
global.initMatrix = this;
if (prevState === null) {
this.roomList = new RoomList(this.matrixClient);
this.accountData = new AccountData(this.roomList);
this.roomsInput = new RoomsInput(this.matrixClient);
this.notifications = new Notifications(this.roomList);
this.emit('init_loading_finished');
}
},
RECONNECTING: () => {
console.log('RECONNECTING state');
},
CATCHUP: () => {
console.log('CATCHUP state');
},
ERROR: () => {
console.log('ERROR state');
},
STOPPED: () => {
console.log('STOPPED state');
},
};
this.matrixClient.on('sync', (state, prevState) => sync[state](prevState));
}
listenEvents() {
this.matrixClient.on('Session.logged_out', () => {
this.matrixClient.stopClient();
this.matrixClient.clearStores();
window.localStorage.clear();
window.location.reload();
});
}
}
const initMatrix = new InitMatrix();
export default initMatrix;