From 533f2c2c98e37015d87cfa0b6024223c2a6e2430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 17 Aug 2021 09:51:48 +0200 Subject: [PATCH] Properly listen for call_state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous thing should have never worked, since CallsChanged doesn't get emitted when a call is answered Signed-off-by: Šimon Brandner --- src/components/structures/LoggedInView.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index 85fca1ae77..4a8b77abec 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -55,7 +55,7 @@ import { getKeyBindingsManager, NavigationAction, RoomAction } from '../../KeyBi import { IOpts } from "../../createRoom"; import SpacePanel from "../views/spaces/SpacePanel"; import { replaceableComponent } from "../../utils/replaceableComponent"; -import CallHandler, { CallHandlerEvent } from '../../CallHandler'; +import CallHandler from '../../CallHandler'; import { MatrixCall } from 'matrix-js-sdk/src/webrtc/call'; import AudioFeedArrayForCall from '../views/voip/AudioFeedArrayForCall'; import RoomView from './RoomView'; @@ -142,6 +142,7 @@ interface IState { class LoggedInView extends React.Component { static displayName = 'LoggedInView'; + private dispatcherRef: string; protected readonly _matrixClient: MatrixClient; protected readonly _roomView: React.RefObject; protected readonly _resizeContainer: React.RefObject; @@ -172,7 +173,7 @@ class LoggedInView extends React.Component { componentDidMount() { document.addEventListener('keydown', this.onNativeKeyDown, false); - CallHandler.sharedInstance().addListener(CallHandlerEvent.CallsChanged, this.onCallsChanged); + this.dispatcherRef = dis.register(this.onAction); this.updateServerNoticeEvents(); @@ -197,7 +198,7 @@ class LoggedInView extends React.Component { componentWillUnmount() { document.removeEventListener('keydown', this.onNativeKeyDown, false); - CallHandler.sharedInstance().removeListener(CallHandlerEvent.CallsChanged, this.onCallsChanged); + dis.unregister(this.dispatcherRef); this._matrixClient.removeListener("accountData", this.onAccountData); this._matrixClient.removeListener("sync", this.onSync); this._matrixClient.removeListener("RoomState.events", this.onRoomStateEvents); @@ -205,10 +206,16 @@ class LoggedInView extends React.Component { this.resizer.detach(); } - private onCallsChanged = () => { - this.setState({ - activeCalls: CallHandler.sharedInstance().getAllActiveCalls(), - }); + private onAction = (payload): void => { + switch (payload.action) { + case 'call_state': { + const activeCalls = CallHandler.sharedInstance().getAllActiveCalls(); + if (activeCalls !== this.state.activeCalls) { + this.setState({ activeCalls }); + } + break; + } + } }; public canResetTimelineInRoom = (roomId: string) => {