mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
offload creating an olm session to the olm worker
so IE11 doesn't lock up when you start typing
This commit is contained in:
parent
bd5771e449
commit
5f6ad91ff2
@ -149,10 +149,14 @@ export class Account {
|
||||
}
|
||||
}
|
||||
|
||||
createOutboundOlmSession(theirIdentityKey, theirOneTimeKey) {
|
||||
async createOutboundOlmSession(theirIdentityKey, theirOneTimeKey) {
|
||||
const newSession = new this._olm.Session();
|
||||
try {
|
||||
newSession.create_outbound(this._account, theirIdentityKey, theirOneTimeKey);
|
||||
if (this._olmWorker) {
|
||||
await this._olmWorker.createOutboundOlmSession(this._account, newSession, theirIdentityKey, theirOneTimeKey);
|
||||
} else {
|
||||
newSession.create_outbound(this._account, theirIdentityKey, theirOneTimeKey);
|
||||
}
|
||||
return newSession;
|
||||
} catch (err) {
|
||||
newSession.free();
|
||||
|
@ -37,6 +37,12 @@ export class OlmWorker {
|
||||
account.unpickle("", pickle);
|
||||
}
|
||||
|
||||
async createOutboundSession(account, newSession, theirIdentityKey, theirOneTimeKey) {
|
||||
const accountPickle = account.pickle("");
|
||||
const sessionPickle = await this._workerPool.send({type: "olm_create_outbound", accountPickle, theirIdentityKey, theirOneTimeKey}).response();
|
||||
newSession.unpickle("", sessionPickle);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this._workerPool.dispose();
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ export class Encryption {
|
||||
try {
|
||||
for (const target of newEncryptionTargets) {
|
||||
const {device, oneTimeKey} = target;
|
||||
target.session = this._account.createOutboundOlmSession(device.curve25519Key, oneTimeKey);
|
||||
target.session = await this._account.createOutboundOlmSession(device.curve25519Key, oneTimeKey);
|
||||
}
|
||||
this._storeSessions(newEncryptionTargets, timestamp);
|
||||
} catch (err) {
|
||||
|
@ -136,6 +136,18 @@ class MessageHandler {
|
||||
account.generate_one_time_keys(otkAmount);
|
||||
this._checkRandomValuesUsed();
|
||||
return account.pickle("");
|
||||
_olmCreateOutbound(accountPickle, theirIdentityKey, theirOneTimeKey) {
|
||||
return this._toMessage(() => {
|
||||
const account = new this._olm.Account();
|
||||
const newSession = new this._olm.Session();
|
||||
try {
|
||||
account.unpickle("", accountPickle);
|
||||
newSession.create_outbound(account, newSession, theirIdentityKey, theirOneTimeKey);
|
||||
return newSession.pickle("");
|
||||
} finally {
|
||||
account.free();
|
||||
newSession.free();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -149,6 +161,8 @@ class MessageHandler {
|
||||
this._sendReply(message, this._megolmDecrypt(message.sessionKey, message.ciphertext));
|
||||
} else if (type === "olm_create_account_otks") {
|
||||
this._sendReply(message, this._olmCreateAccountAndOTKs(message.randomValues, message.otkAmount));
|
||||
} else if (type === "olm_create_outbound") {
|
||||
this._sendReply(message, this._olmCreateOutbound(message.accountPickle, message.theirIdentityKey, message.theirOneTimeKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user