From fc8a867e8eda55a7fd59e6d77ffecdf29f851e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Mon, 25 Oct 2021 23:02:28 +0200 Subject: [PATCH] Start processing member state events only after we've set out own (#2000) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This avoids a race condition where the other side would first receive the to-device messages and only then the member state event which would result in the call being ignored Signed-off-by: Šimon Brandner --- src/webrtc/groupCall.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/webrtc/groupCall.ts b/src/webrtc/groupCall.ts index 57981759b..1f1f86199 100644 --- a/src/webrtc/groupCall.ts +++ b/src/webrtc/groupCall.ts @@ -239,7 +239,7 @@ export class GroupCall extends EventEmitter { this.addParticipant(this.room.getMember(this.client.getUserId())); - this.sendMemberStateEvent(); + const sendMemberStateEventPromise = this.sendMemberStateEvent(); this.activeSpeaker = null; @@ -262,9 +262,14 @@ export class GroupCall extends EventEmitter { logger.log("Processing initial members"); - for (const stateEvent of memberStateEvents) { - this.onMemberStateChanged(stateEvent); - } + // This avoids a race condition where the other side would first receive + // the to-device messages and only then the member state event which + // would result in the call being ignored + sendMemberStateEventPromise.then(() => { + for (const stateEvent of memberStateEvents) { + this.onMemberStateChanged(stateEvent); + } + }); this.client.on("Call.incoming", this.onIncomingCall);