From cd8e7e3076c3c69d31b56d45b4542fdcf983924e Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 2 Sep 2021 15:51:44 +0100 Subject: [PATCH] Move error dialog to the new check So we just check for an existing call in one place where it doesn't race --- src/CallHandler.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index aa0a037423..adcc9024e5 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -754,7 +754,15 @@ export default class CallHandler extends EventEmitter { console.log("Current turn creds expire in " + timeUntilTurnCresExpire + " ms"); const call = MatrixClientPeg.get().createCall(mappedRoomId); - this.addCallForRoom(roomId, call); + try { + this.addCallForRoom(roomId, call); + } catch (e) { + Modal.createTrackedDialog('Call Handler', 'Existing Call with user', ErrorDialog, { + title: _t('Already in call'), + description: _t("You're already in a call with this person."), + }); + return; + } if (transferee) { this.transferees[call.callId] = transferee; } @@ -806,14 +814,8 @@ export default class CallHandler extends EventEmitter { return; } - console.log("getting call for room " + room.roomId); - if (this.getCallForRoom(room.roomId)) { - Modal.createTrackedDialog('Call Handler', 'Existing Call with user', ErrorDialog, { - title: _t('Already in call'), - description: _t("You're already in a call with this person."), - }); - return; - } + // We leave the check for whether there's already a call in this room until later, + // otherwise it can race. const members = room.getJoinedMembers(); if (members.length <= 1) {