From a45b7e50cdebddbdea186b22536b28ee9d16915c Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 1 Oct 2020 11:28:42 +0100 Subject: [PATCH] Fix the call preview when not in same room as the call Classic failure of an ES6 map also being a regular object :( Fixes https://github.com/vector-im/element-web/issues/15343 --- src/CallHandler.tsx | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/CallHandler.tsx b/src/CallHandler.tsx index 62b91f938b..2d3f3a7537 100644 --- a/src/CallHandler.tsx +++ b/src/CallHandler.tsx @@ -110,11 +110,9 @@ export default class CallHandler { } getAnyActiveCall() { - const roomsWithCalls = Object.keys(this.calls); - for (let i = 0; i < roomsWithCalls.length; i++) { - if (this.calls.get(roomsWithCalls[i]) && - this.calls.get(roomsWithCalls[i]).call_state !== "ended") { - return this.calls.get(roomsWithCalls[i]); + for (const call of this.calls.values()) { + if (call.state !== "ended") { + return call; } } return null; @@ -180,7 +178,7 @@ export default class CallHandler { }); }); call.on("hangup", () => { - this.setCallState(undefined, call.roomId, "ended"); + this.removeCallForRoom(call.roomId); }); // map web rtc states to dummy UI state // ringing|ringback|connected|ended|busy|stop_ringback|stop_ringing @@ -192,7 +190,7 @@ export default class CallHandler { this.setCallState(call, call.roomId, "ringback"); this.play("ringbackAudio"); } else if (newState === "ended" && oldState === "connected") { - this.setCallState(undefined, call.roomId, "ended"); + this.removeCallForRoom(call.roomId); this.pause("ringbackAudio"); this.play("callendAudio"); } else if (newState === "ended" && oldState === "invite_sent" && @@ -223,7 +221,11 @@ export default class CallHandler { console.log( `Call state in ${roomId} changed to ${status} (${call ? call.call_state : "-"})`, ); - this.calls.set(roomId, call); + if (call) { + this.calls.set(roomId, call); + } else { + this.calls.delete(roomId); + } if (status === "ringing") { this.play("ringAudio"); @@ -241,6 +243,10 @@ export default class CallHandler { }); } + private removeCallForRoom(roomId: string) { + this.setCallState(null, roomId, null); + } + private showICEFallbackPrompt() { const cli = MatrixClientPeg.get(); const code = sub => {sub}; @@ -283,7 +289,7 @@ export default class CallHandler { } else if (payload.type === 'screensharing') { const screenCapErrorString = PlatformPeg.get().screenCaptureErrorString(); if (screenCapErrorString) { - this.setCallState(undefined, newCall.roomId, "ended"); + this.removeCallForRoom(newCall.roomId); console.log("Can't capture screen: " + screenCapErrorString); Modal.createTrackedDialog('Call Handler', 'Unable to capture screen', ErrorDialog, { title: _t('Unable to capture screen'), @@ -376,7 +382,7 @@ export default class CallHandler { return; // no call to hangup } this.calls.get(payload.room_id).hangup(); - this.setCallState(null, payload.room_id, "ended"); + this.removeCallForRoom(payload.room_id); break; case 'answer': if (!this.calls.get(payload.room_id)) {