From 9cd660752060bf761b24b34d5ea25dc370dda3b2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 29 Jan 2020 15:16:54 +0100 Subject: [PATCH] attempt to switch start event if we already have a verifier --- .../verification/request/VerificationRequest.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/crypto/verification/request/VerificationRequest.js b/src/crypto/verification/request/VerificationRequest.js index d9bfeef17..6b3ddc1de 100644 --- a/src/crypto/verification/request/VerificationRequest.js +++ b/src/crypto/verification/request/VerificationRequest.js @@ -521,10 +521,18 @@ export class VerificationRequest extends EventEmitter { } // only pass events from the other side to the verifier, // no remote echos of our own events - if (this._verifier && !isRemoteEcho && !this.observeOnly) { - if (type === CANCEL_TYPE || (this._verifier.events - && this._verifier.events.includes(type))) { - this._verifier.handleEvent(event); + if (this._verifier && !this.observeOnly) { + const oldEvent = this._verifier.startEvent; + // if the verifier does not have a startEvent, it is because it's still sending and we are on the initator side + const oldSender = oldEvent ? oldEvent.getSender() : this._client.getUserId(); + const newEventWinsRace = event.getSender() < oldSender; + if (this._verifier.canSwitchStartEvent(event) && newEventWinsRace) { + this._verifier.switchStartEvent(event); + } else if (!isRemoteEcho) { + if (type === CANCEL_TYPE || (this._verifier.events + && this._verifier.events.includes(type))) { + this._verifier.handleEvent(event); + } } }