From 63a9dc9e9111a16b83780ad315e0b2b4d36e54d0 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 26 Jan 2022 15:19:54 +0000 Subject: [PATCH] Fix soft-crash when hanging up Jitsi via PIP --- .../views/voip/CallView/CallViewHeader.tsx | 3 +- src/components/views/voip/PipView.tsx | 28 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/components/views/voip/CallView/CallViewHeader.tsx b/src/components/views/voip/CallView/CallViewHeader.tsx index 28baa68f314..00a94a3e263 100644 --- a/src/components/views/voip/CallView/CallViewHeader.tsx +++ b/src/components/views/voip/CallView/CallViewHeader.tsx @@ -75,8 +75,7 @@ const CallViewHeader: React.FC = ({ onPipMouseDown, }) => { const [callRoom, onHoldCallRoom] = callRooms; - const callRoomName = callRoom.name; - const { roomId } = callRoom; + const { roomId, name: callRoomName } = callRoom; if (!pipMode) { return
diff --git a/src/components/views/voip/PipView.tsx b/src/components/views/voip/PipView.tsx index 654d04d2992..395763b157f 100644 --- a/src/components/views/voip/PipView.tsx +++ b/src/components/views/voip/PipView.tsx @@ -199,10 +199,7 @@ export default class PipView extends React.Component { }; private onActiveWidgetStoreUpdate = (): void => { - this.setState({ - persistentWidgetId: ActiveWidgetStore.instance.getPersistentWidgetId(), - }); - this.updateShowWidgetInPip(); + this.updateShowWidgetInPip(ActiveWidgetStore.instance.getPersistentWidgetId()); }; private updateCalls = (): void => { @@ -237,24 +234,23 @@ export default class PipView extends React.Component { } }; - public updateShowWidgetInPip() { - const wId = this.state.persistentWidgetId; - + // Accepts a persistentWidgetId to be able to skip awaiting the setState for persistentWidgetId + public updateShowWidgetInPip(persistentWidgetId = this.state.persistentWidgetId) { let userIsPartOfTheRoom = false; let fromAnotherRoom = false; let notVisible = false; - if (wId) { - const persistentWidgetInRoomId = ActiveWidgetStore.instance.getRoomId(wId); + if (persistentWidgetId) { + const persistentWidgetInRoomId = ActiveWidgetStore.instance.getRoomId(persistentWidgetId); const persistentWidgetInRoom = MatrixClientPeg.get().getRoom(persistentWidgetInRoomId); // Sanity check the room - the widget may have been destroyed between render cycles, and // thus no room is associated anymore. - if (!persistentWidgetInRoom) return null; - - const wls = WidgetLayoutStore.instance; - notVisible = !wls.isVisibleOnScreen(persistentWidgetInRoom, wId); - userIsPartOfTheRoom = persistentWidgetInRoom.getMyMembership() == "join"; - fromAnotherRoom = this.state.viewedRoomId !== persistentWidgetInRoomId; + if (persistentWidgetInRoom) { + const wls = WidgetLayoutStore.instance; + notVisible = !wls.isVisibleOnScreen(persistentWidgetInRoom, persistentWidgetId); + userIsPartOfTheRoom = persistentWidgetInRoom.getMyMembership() == "join"; + fromAnotherRoom = this.state.viewedRoomId !== persistentWidgetInRoomId; + } } // The widget should only be shown as a persistent app (in a floating pip container) if it is not visible on screen @@ -263,7 +259,7 @@ export default class PipView extends React.Component { (fromAnotherRoom && userIsPartOfTheRoom) || (notVisible && userIsPartOfTheRoom); - this.setState({ showWidgetInPip }); + this.setState({ showWidgetInPip, persistentWidgetId }); } public render() {