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) => {