Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createClient(hs_url, is_url, user_id, access_token) {
var opts = {
baseUrl: hs_url,
idBaseUrl: is_url,
accessToken: access_token,
userId: user_id
};
if (localStorage) {
opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
opts.deviceId = deviceId();
}
matrixClient = Matrix.createClient(opts);
}
async function makeMatrixClient(userId, deviceId, platform, storage, accessToken, options) {
const db = sql.db(platform.getSqliteDB(), platform.getSqliteKey());
const ownerId = userId + '/' + deviceId;
const store = new SqliteStore({ userId: ownerId, db: db });
await store.startup();
const matrixClient = Matrix.createClient({
baseUrl: options.homeServerURL,
idBaseUrl: options.identityServerURL,
store: store,
sessionStore: new Matrix.WebStorageSessionStore(storage),
cryptoStore: new CryptoSqliteStore(db, ownerId),
userId: userId,
deviceId: deviceId,
accessToken: accessToken
});
if (global.Olm)
matrixClient.initCrypto();
return matrixClient;
}
export default function createMatrixClient(opts, useIndexedDb) {
if (useIndexedDb === undefined) useIndexedDb = true;
const storeOpts = {
useAuthorizationHeader: true,
};
if (localStorage) {
storeOpts.sessionStore = new Matrix.WebStorageSessionStore(localStorage);
}
if (indexedDB && localStorage && useIndexedDb) {
storeOpts.store = new Matrix.IndexedDBStore({
indexedDB: indexedDB,
dbName: "riot-web-sync",
localStorage: localStorage,
workerScript: createMatrixClient.indexedDbWorkerScript,
});
}
opts = Object.assign(storeOpts, opts);
return Matrix.createClient(opts);
}