From a6cde3256ec0ed2fc6e893c3a91dd3a1f4698b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sun, 15 Aug 2021 12:56:29 +0200 Subject: [PATCH] Properly handle call change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/components/views/voip/CallView.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/views/voip/CallView.tsx b/src/components/views/voip/CallView.tsx index a6ae71713b9..9d822912862 100644 --- a/src/components/views/voip/CallView.tsx +++ b/src/components/views/voip/CallView.tsx @@ -111,7 +111,7 @@ export default class CallView extends React.Component { constructor(props: IProps) { super(props); - const { primary, secondary } = this.getOrderedFeeds(this.props.call.getFeeds()); + const { primary, secondary } = CallView.getOrderedFeeds(this.props.call.getFeeds()); this.state = { isLocalOnHold: this.props.call.isLocalOnHold(), @@ -147,7 +147,16 @@ export default class CallView extends React.Component { dis.unregister(this.dispatcherRef); } - public componentDidUpdate(prevProps) { + static getDerivedStateFromProps(props: IProps): Partial { + const { primary, secondary } = CallView.getOrderedFeeds(props.call.getFeeds()); + + return { + primaryFeed: primary, + secondaryFeeds: secondary, + }; + } + + public componentDidUpdate(prevProps: IProps): void { if (this.props.call === prevProps.call) return; this.setState({ @@ -201,7 +210,7 @@ export default class CallView extends React.Component { }; private onFeedsChanged = (newFeeds: Array) => { - const { primary, secondary } = this.getOrderedFeeds(newFeeds); + const { primary, secondary } = CallView.getOrderedFeeds(newFeeds); this.setState({ primaryFeed: primary, secondaryFeeds: secondary, @@ -226,7 +235,7 @@ export default class CallView extends React.Component { this.buttonsRef.current?.showControls(); }; - private getOrderedFeeds(feeds: Array): { primary: CallFeed, secondary: Array } { + static getOrderedFeeds(feeds: Array): { primary: CallFeed, secondary: Array } { let primary; // Try to use a screensharing as primary, a remote one if possible