Files
ThreadNet-Web/src/components/views/voip/LegacyCallView.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

587 lines
23 KiB
TypeScript
Raw Normal View History

2020-07-06 22:42:46 +01:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2021, 2022 Šimon Brandner <simon.bra.ag@gmail.com>
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
2020-07-06 22:42:46 +01:00
Copyright 2015, 2016 OpenMarket Ltd
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2020-07-06 22:42:46 +01:00
*/
2020-07-07 15:11:08 +01:00
2022-05-04 17:16:38 +02:00
import React, { createRef } from "react";
2025-02-05 13:25:06 +00:00
import { CallEvent, CallState, type MatrixCall } from "matrix-js-sdk/src/webrtc/call";
2021-10-22 17:23:32 -05:00
import classNames from "classnames";
2025-02-05 13:25:06 +00:00
import { type CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";
2021-10-22 17:23:32 -05:00
import { SDPStreamMetadataPurpose } from "matrix-js-sdk/src/webrtc/callEventTypes";
2020-07-06 22:42:46 +01:00
import dis from "../../../dispatcher/dispatcher";
import LegacyCallHandler from "../../../LegacyCallHandler";
2021-06-29 13:11:58 +01:00
import { MatrixClientPeg } from "../../../MatrixClientPeg";
2020-12-18 19:35:41 +00:00
import { _t, _td } from "../../../languageHandler";
2021-03-07 08:13:35 +01:00
import VideoFeed from "./VideoFeed";
2020-07-06 22:42:46 +01:00
import RoomAvatar from "../avatars/RoomAvatar";
2020-11-18 14:22:38 +00:00
import AccessibleButton from "../elements/AccessibleButton";
2020-11-26 14:35:09 +00:00
import { avatarUrlForMember } from "../../../Avatar";
import LegacyCallViewSidebar from "./LegacyCallViewSidebar";
import LegacyCallViewHeader from "./LegacyCallView/LegacyCallViewHeader";
import LegacyCallViewButtons from "./LegacyCallView/LegacyCallViewButtons";
2025-02-05 13:25:06 +00:00
import { type ActionPayload } from "../../../dispatcher/payloads";
2022-02-23 10:12:04 +01:00
import { getKeyBindingsManager } from "../../../KeyBindingsManager";
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
2021-05-07 21:34:56 +02:00
2020-07-06 22:42:46 +01:00
interface IProps {
2021-08-03 14:03:35 +02:00
// The call for us to display
call: MatrixCall;
2020-12-03 17:45:49 +00:00
2021-08-03 14:03:35 +02:00
// Another ongoing call to display information about
secondaryCall?: MatrixCall;
2020-07-06 22:42:46 +01:00
// a callback which is called when the content in the LegacyCallView changes
2021-08-03 14:03:35 +02:00
// in a way that is likely to cause a resize.
2021-08-06 16:43:20 +02:00
onResize?: (event: Event) => void;
2020-07-06 22:42:46 +01:00
2021-08-03 14:03:35 +02:00
// Whether this call view is for picture-in-picture mode
// otherwise, it's the larger call view when viewing the room the call is in.
// This is sort of a proxy for a number of things but we currently have no
// need to control those things separately, so this is simpler.
pipMode?: boolean;
2021-05-02 16:23:35 +02:00
// Used for dragging the PiP LegacyCallView
2021-08-03 13:30:14 +02:00
onMouseDownOnHeader?: (event: React.MouseEvent<Element, MouseEvent>) => void;
showApps?: boolean;
2020-07-06 22:42:46 +01:00
}
interface IState {
2021-07-01 23:23:03 +01:00
isLocalOnHold: boolean;
isRemoteOnHold: boolean;
micMuted: boolean;
vidMuted: boolean;
screensharing: boolean;
2021-07-01 23:23:03 +01:00
callState: CallState;
2022-05-04 17:16:38 +02:00
primaryFeed?: CallFeed;
secondaryFeed?: CallFeed;
sidebarFeeds: Array<CallFeed>;
sidebarShown: boolean;
2020-10-29 17:56:24 +00:00
}
function getFullScreenElement(): Element | null {
2020-10-29 17:56:24 +00:00
return (
document.fullscreenElement ||
// moz omitted because firefox supports this unprefixed now (webkit here for safari)
document.webkitFullscreenElement ||
document.msFullscreenElement
);
}
function requestFullscreen(element: Element): void {
2020-10-29 17:56:24 +00:00
const method =
element.requestFullscreen ||
// moz omitted since firefox supports unprefixed now
element.webkitRequestFullScreen ||
element.msRequestFullscreen;
if (method) method.call(element);
}
function exitFullscreen(): void {
2020-10-29 17:56:24 +00:00
const exitMethod = document.exitFullscreen || document.webkitExitFullscreen || document.msExitFullscreen;
if (exitMethod) exitMethod.call(document);
2020-07-06 22:42:46 +01:00
}
export default class LegacyCallView extends React.Component<IProps, IState> {
private dispatcherRef?: string;
2022-05-04 17:16:38 +02:00
private contentWrapperRef = createRef<HTMLDivElement>();
private buttonsRef = createRef<LegacyCallViewButtons>();
2020-11-26 14:35:09 +00:00
public constructor(props: IProps) {
2020-07-06 22:42:46 +01:00
super(props);
const { primary, secondary, sidebar } = LegacyCallView.getOrderedFeeds(this.props.call.getFeeds());
2021-06-12 09:19:58 +02:00
2020-07-06 22:42:46 +01:00
this.state = {
2020-12-03 17:45:49 +00:00
isLocalOnHold: this.props.call.isLocalOnHold(),
isRemoteOnHold: this.props.call.isRemoteOnHold(),
micMuted: this.props.call.isMicrophoneMuted(),
vidMuted: this.props.call.isLocalVideoMuted(),
2021-05-07 21:35:32 +02:00
screensharing: this.props.call.isScreensharing(),
2020-12-03 17:45:49 +00:00
callState: this.props.call.state,
2021-06-12 09:19:58 +02:00
primaryFeed: primary,
2022-05-04 17:16:38 +02:00
secondaryFeed: secondary,
sidebarFeeds: sidebar,
2021-06-12 17:20:13 +02:00
sidebarShown: true,
2021-06-29 13:11:58 +01:00
};
2020-07-06 22:42:46 +01:00
}
2022-05-04 17:16:38 +02:00
public componentDidMount(): void {
this.updateCallListeners(null, this.props.call);
2020-07-06 22:42:46 +01:00
this.dispatcherRef = dis.register(this.onAction);
2020-11-19 15:15:31 +00:00
document.addEventListener("keydown", this.onNativeKeyDown);
2020-07-06 22:42:46 +01:00
}
2022-05-04 17:16:38 +02:00
public componentWillUnmount(): void {
2020-12-03 17:45:49 +00:00
if (getFullScreenElement()) {
exitFullscreen();
}
2020-11-19 15:15:31 +00:00
document.removeEventListener("keydown", this.onNativeKeyDown);
2020-12-03 17:45:49 +00:00
this.updateCallListeners(this.props.call, null);
dis.unregister(this.dispatcherRef);
2020-07-06 22:42:46 +01:00
}
public static getDerivedStateFromProps(props: IProps): Partial<IState> {
const { primary, secondary, sidebar } = LegacyCallView.getOrderedFeeds(props.call.getFeeds());
2021-08-15 12:56:29 +02:00
return {
primaryFeed: primary,
2022-05-04 17:16:38 +02:00
secondaryFeed: secondary,
sidebarFeeds: sidebar,
2021-08-15 12:56:29 +02:00
};
}
public componentDidUpdate(prevProps: IProps): void {
2020-12-03 17:45:49 +00:00
if (this.props.call === prevProps.call) return;
this.setState({
isLocalOnHold: this.props.call.isLocalOnHold(),
isRemoteOnHold: this.props.call.isRemoteOnHold(),
micMuted: this.props.call.isMicrophoneMuted(),
vidMuted: this.props.call.isLocalVideoMuted(),
callState: this.props.call.state,
});
this.updateCallListeners(null, this.props.call);
}
2022-05-04 17:16:38 +02:00
private onAction = (payload: ActionPayload): void => {
2020-10-29 17:56:24 +00:00
switch (payload.action) {
case "video_fullscreen": {
2022-05-04 17:16:38 +02:00
if (!this.contentWrapperRef.current) {
2020-10-29 17:56:24 +00:00
return;
}
if (payload.fullscreen) {
2022-05-04 17:16:38 +02:00
requestFullscreen(this.contentWrapperRef.current);
2020-10-29 17:56:24 +00:00
} else if (getFullScreenElement()) {
exitFullscreen();
}
break;
}
2020-07-06 22:42:46 +01:00
}
2020-07-07 15:40:05 +01:00
};
2020-07-06 22:42:46 +01:00
private updateCallListeners(oldCall: MatrixCall | null, newCall: MatrixCall | null): void {
2020-10-29 17:56:24 +00:00
if (oldCall === newCall) return;
2020-11-26 14:35:09 +00:00
if (oldCall) {
2020-12-03 17:45:49 +00:00
oldCall.removeListener(CallEvent.State, this.onCallState);
2020-11-26 14:35:09 +00:00
oldCall.removeListener(CallEvent.LocalHoldUnhold, this.onCallLocalHoldUnhold);
oldCall.removeListener(CallEvent.RemoteHoldUnhold, this.onCallRemoteHoldUnhold);
2021-03-07 08:13:35 +01:00
oldCall.removeListener(CallEvent.FeedsChanged, this.onFeedsChanged);
2020-11-26 14:35:09 +00:00
}
if (newCall) {
2020-12-03 17:45:49 +00:00
newCall.on(CallEvent.State, this.onCallState);
2020-11-26 14:35:09 +00:00
newCall.on(CallEvent.LocalHoldUnhold, this.onCallLocalHoldUnhold);
newCall.on(CallEvent.RemoteHoldUnhold, this.onCallRemoteHoldUnhold);
2021-03-07 08:13:35 +01:00
newCall.on(CallEvent.FeedsChanged, this.onFeedsChanged);
2020-11-26 14:35:09 +00:00
}
2020-07-06 22:42:46 +01:00
}
2022-05-04 17:16:38 +02:00
private onCallState = (state: CallState): void => {
2020-12-03 17:45:49 +00:00
this.setState({
callState: state,
});
};
2022-05-04 17:16:38 +02:00
private onFeedsChanged = (newFeeds: Array<CallFeed>): void => {
const { primary, secondary, sidebar } = LegacyCallView.getOrderedFeeds(newFeeds);
2021-06-12 09:19:58 +02:00
this.setState({
primaryFeed: primary,
2022-05-04 17:16:38 +02:00
secondaryFeed: secondary,
sidebarFeeds: sidebar,
micMuted: this.props.call.isMicrophoneMuted(),
vidMuted: this.props.call.isLocalVideoMuted(),
2021-06-12 09:19:58 +02:00
});
2021-04-19 07:42:32 +02:00
};
2021-03-07 08:13:35 +01:00
2022-05-04 17:16:38 +02:00
private onCallLocalHoldUnhold = (): void => {
2020-10-29 17:56:24 +00:00
this.setState({
2020-12-03 17:45:49 +00:00
isLocalOnHold: this.props.call.isLocalOnHold(),
2020-10-29 17:56:24 +00:00
});
};
2022-05-04 17:16:38 +02:00
private onCallRemoteHoldUnhold = (): void => {
2020-11-26 14:35:09 +00:00
this.setState({
2020-12-03 17:45:49 +00:00
isRemoteOnHold: this.props.call.isRemoteOnHold(),
2020-11-26 14:35:09 +00:00
// update both here because isLocalOnHold changes when we hold the call too
2020-12-03 17:45:49 +00:00
isLocalOnHold: this.props.call.isLocalOnHold(),
2020-11-26 14:35:09 +00:00
});
};
2022-05-04 17:16:38 +02:00
private onMouseMove = (): void => {
2021-08-08 11:20:17 +02:00
this.buttonsRef.current?.showControls();
2021-06-29 13:11:58 +01:00
};
2020-11-19 15:15:31 +00:00
public static getOrderedFeeds(feeds: Array<CallFeed>): {
2022-05-04 17:16:38 +02:00
primary?: CallFeed;
secondary?: CallFeed;
sidebar: Array<CallFeed>;
} {
if (feeds.length <= 2) {
return {
primary: feeds.find((feed) => !feed.isLocal()),
secondary: feeds.find((feed) => feed.isLocal()),
sidebar: [],
};
}
let primary: CallFeed | undefined;
2021-06-12 09:19:58 +02:00
2021-07-21 16:20:09 +02:00
// Try to use a screensharing as primary, a remote one if possible
const screensharingFeeds = feeds.filter((feed) => feed.purpose === SDPStreamMetadataPurpose.Screenshare);
primary = screensharingFeeds.find((feed) => !feed.isLocal()) || screensharingFeeds[0];
2021-06-12 09:19:58 +02:00
// If we didn't find remote screen-sharing stream, try to find any remote stream
if (!primary) {
primary = feeds.find((feed) => !feed.isLocal());
}
2022-05-04 17:16:38 +02:00
const sidebar = [...feeds];
2021-06-12 09:19:58 +02:00
// Remove the primary feed from the array
2022-05-04 17:16:38 +02:00
if (primary) sidebar.splice(sidebar.indexOf(primary), 1);
sidebar.sort((a, b) => {
2021-06-12 09:19:58 +02:00
if (a.isLocal() && !b.isLocal()) return -1;
if (!a.isLocal() && b.isLocal()) return 1;
return 0;
});
2022-05-04 17:16:38 +02:00
return { primary, sidebar };
2021-05-10 13:21:02 +02:00
}
private onMaximizeClick = (): void => {
dis.dispatch({
action: "video_fullscreen",
fullscreen: true,
});
};
private onMicMuteClick = async (): Promise<void> => {
2020-11-18 14:22:38 +00:00
const newVal = !this.state.micMuted;
this.setState({ micMuted: await this.props.call.setMicrophoneMuted(newVal) });
2021-06-29 13:11:58 +01:00
};
2020-11-18 14:22:38 +00:00
private onVidMuteClick = async (): Promise<void> => {
2020-11-18 14:22:38 +00:00
const newVal = !this.state.vidMuted;
this.setState({ vidMuted: await this.props.call.setLocalVideoMuted(newVal) });
2021-06-29 13:11:58 +01:00
};
2020-11-18 14:22:38 +00:00
2021-07-20 13:47:07 +02:00
private onScreenshareClick = async (): Promise<void> => {
let isScreensharing;
if (this.state.screensharing) {
isScreensharing = await this.props.call.setScreensharingEnabled(false);
} else {
isScreensharing = await this.props.call.setScreensharingEnabled(true);
}
2021-07-20 16:58:44 +02:00
this.setState({
sidebarShown: true,
screensharing: isScreensharing,
});
};
2021-05-07 21:35:32 +02:00
2020-11-19 15:15:31 +00:00
// we register global shortcuts here, they *must not conflict* with local shortcuts elsewhere or both will fire
// Note that this assumes we always have a LegacyCallView on screen at any given time
// LegacyCallHandler would probably be a better place for this
2023-02-13 11:39:16 +00:00
private onNativeKeyDown = (ev: KeyboardEvent): void => {
2020-11-19 15:15:31 +00:00
let handled = false;
2022-02-23 10:12:04 +01:00
const callAction = getKeyBindingsManager().getCallAction(ev);
switch (callAction) {
case KeyBindingAction.ToggleMicInCall:
this.onMicMuteClick();
// show the controls to give feedback
this.buttonsRef.current?.showControls();
handled = true;
2020-11-19 15:15:31 +00:00
break;
2022-02-23 10:12:04 +01:00
case KeyBindingAction.ToggleWebcamInCall:
this.onVidMuteClick();
// show the controls to give feedback
this.buttonsRef.current?.showControls();
handled = true;
2020-11-19 15:15:31 +00:00
break;
}
if (handled) {
ev.stopPropagation();
ev.preventDefault();
}
};
2021-07-20 13:47:07 +02:00
private onCallResumeClick = (): void => {
const userFacingRoomId = LegacyCallHandler.instance.roomIdForCall(this.props.call);
if (userFacingRoomId) LegacyCallHandler.instance.setActiveCallRoomId(userFacingRoomId);
2021-06-29 13:11:58 +01:00
};
2020-12-03 17:45:49 +00:00
2021-07-20 13:47:07 +02:00
private onTransferClick = (): void => {
const transfereeCall = LegacyCallHandler.instance.getTransfereeForCallId(this.props.call.callId);
if (transfereeCall) this.props.call.transferToCall(transfereeCall);
2021-06-29 13:11:58 +01:00
};
2021-03-25 19:56:21 +00:00
2021-07-20 13:47:07 +02:00
private onHangupClick = (): void => {
const roomId = LegacyCallHandler.instance.roomIdForCall(this.props.call);
if (roomId) LegacyCallHandler.instance.hangupOrReject(roomId);
};
2020-10-29 17:56:24 +00:00
2021-07-20 13:47:07 +02:00
private onToggleSidebar = (): void => {
2021-08-08 11:20:17 +02:00
this.setState({ sidebarShown: !this.state.sidebarShown });
};
2021-06-12 17:20:13 +02:00
2021-06-12 16:32:01 +02:00
private renderCallControls(): JSX.Element {
const { call, pipMode } = this.props;
2022-05-04 17:16:38 +02:00
const { callState, micMuted, vidMuted, screensharing, sidebarShown, secondaryFeed, sidebarFeeds } = this.state;
// If SDPStreamMetadata isn't supported don't show video mute button in voice calls
const vidMuteButtonShown = call.opponentSupportsSDPStreamMetadata() || call.hasLocalUserMediaVideoTrack;
2021-05-13 18:11:47 +02:00
// Screensharing is possible, if we can send a second stream and
// identify it using SDPStreamMetadata or if we can replace the already
// existing usermedia track by a screensharing track. We also need to be
// connected to know the state of the other side
2021-08-08 11:20:17 +02:00
const screensharingButtonShown =
(call.opponentSupportsSDPStreamMetadata() || call.hasLocalUserMediaVideoTrack) &&
call.state === CallState.Connected;
2022-05-04 17:16:38 +02:00
// Show the sidebar button only if there is something to hide/show
const sidebarButtonShown = (secondaryFeed && !secondaryFeed.isVideoMuted()) || sidebarFeeds.length > 0;
2021-01-04 20:01:43 +00:00
// The dial pad & 'more' button actions are only relevant in a connected call
const contextMenuButtonShown = callState === CallState.Connected;
const dialpadButtonShown = callState === CallState.Connected && call.opponentSupportsDTMF();
2021-06-12 16:32:01 +02:00
return (
<LegacyCallViewButtons
2021-08-08 11:20:17 +02:00
ref={this.buttonsRef}
call={call}
pipMode={pipMode}
2021-08-08 11:20:17 +02:00
handlers={{
onToggleSidebarClick: this.onToggleSidebar,
onScreenshareClick: this.onScreenshareClick,
onHangupClick: this.onHangupClick,
onMicMuteClick: this.onMicMuteClick,
onVidMuteClick: this.onVidMuteClick,
}}
buttonsState={{
micMuted: micMuted,
vidMuted: vidMuted,
sidebarShown: sidebarShown,
screensharing: screensharing,
2021-08-08 11:20:17 +02:00
}}
buttonsVisibility={{
vidMute: vidMuteButtonShown,
screensharing: screensharingButtonShown,
sidebar: sidebarButtonShown,
contextMenu: contextMenuButtonShown,
dialpad: dialpadButtonShown,
}}
/>
2021-06-12 16:32:01 +02:00
);
}
2020-12-03 17:45:49 +00:00
private renderToast(): JSX.Element | null {
2022-05-04 17:16:38 +02:00
const { call } = this.props;
const someoneIsScreensharing = call.getFeeds().some((feed) => {
2021-07-21 18:14:21 +02:00
return feed.purpose === SDPStreamMetadataPurpose.Screenshare;
});
2021-06-12 16:32:01 +02:00
2022-05-04 17:16:38 +02:00
if (!someoneIsScreensharing) return null;
2021-06-12 16:32:01 +02:00
2022-05-04 17:16:38 +02:00
const isScreensharing = call.isScreensharing();
const { primaryFeed, sidebarShown } = this.state;
const sharerName = primaryFeed?.getMember()?.name;
if (!sharerName) return null;
2021-03-25 19:56:21 +00:00
let text = isScreensharing ? _t("voip|you_are_presenting") : _t("voip|user_is_presenting", { sharerName });
2022-05-04 17:16:38 +02:00
if (!sidebarShown) {
text += " • " + (call.isLocalVideoMuted() ? _t("voip|camera_disabled") : _t("voip|camera_enabled"));
2020-11-26 14:35:09 +00:00
}
return <div className="mx_LegacyCallView_toast">{text}</div>;
2022-05-04 17:16:38 +02:00
}
private renderContent(): JSX.Element {
const { pipMode, call, onResize } = this.props;
const { isLocalOnHold, isRemoteOnHold, sidebarShown, primaryFeed, secondaryFeed, sidebarFeeds } = this.state;
const callRoomId = LegacyCallHandler.instance.roomIdForCall(call);
const callRoom = (callRoomId ? MatrixClientPeg.safeGet().getRoom(callRoomId) : undefined) ?? undefined;
const avatarSize = pipMode ? "76px" : "160px";
const transfereeCall = LegacyCallHandler.instance.getTransfereeForCallId(call.callId);
2022-05-04 17:16:38 +02:00
const isOnHold = isLocalOnHold || isRemoteOnHold;
let secondaryFeedElement: React.ReactNode;
if (sidebarShown && secondaryFeed && !secondaryFeed.isVideoMuted()) {
secondaryFeedElement = (
<VideoFeed feed={secondaryFeed} call={call} pipMode={pipMode} onResize={onResize} secondary={true} />
2021-06-12 11:03:14 +02:00
);
}
2022-05-04 17:16:38 +02:00
if (transfereeCall || isOnHold) {
const containerClasses = classNames("mx_LegacyCallView_content", {
mx_LegacyCallView_content_hold: isOnHold,
2022-05-04 17:16:38 +02:00
});
const backgroundAvatarUrl = avatarUrlForMember(call.getOpponentMember(), 1024, 1024, "crop");
2020-11-26 14:35:09 +00:00
2022-05-04 17:16:38 +02:00
let holdTransferContent: React.ReactNode;
if (transfereeCall) {
const cli = MatrixClientPeg.safeGet();
const callRoomId = LegacyCallHandler.instance.roomIdForCall(call);
const transferTargetRoom = callRoomId ? cli.getRoom(callRoomId) : null;
const transferTargetName = transferTargetRoom ? transferTargetRoom.name : _t("voip|unknown_person");
const transfereeCallRoomId = LegacyCallHandler.instance.roomIdForCall(transfereeCall);
const transfereeRoom = transfereeCallRoomId ? cli.getRoom(transfereeCallRoomId) : null;
const transfereeName = transfereeRoom ? transfereeRoom.name : _t("voip|unknown_person");
2022-05-04 17:16:38 +02:00
holdTransferContent = (
<div className="mx_LegacyCallView_status">
2022-05-04 17:16:38 +02:00
{_t(
"voip|consulting",
2022-05-04 17:16:38 +02:00
{
transferTarget: transferTargetName,
transferee: transfereeName,
},
{
a: (sub) => (
<AccessibleButton kind="link_inline" onClick={this.onTransferClick}>
2022-05-04 17:16:38 +02:00
{sub}
</AccessibleButton>
),
},
)}
</div>
);
2021-03-07 08:13:35 +01:00
} else {
2022-05-04 17:16:38 +02:00
let onHoldText: React.ReactNode;
if (isRemoteOnHold) {
onHoldText = _t(
LegacyCallHandler.instance.hasAnyUnheldCall()
? _td("voip|call_held_switch")
: _td("voip|call_held_resume"),
2022-05-04 17:16:38 +02:00
{},
{
a: (sub) => (
<AccessibleButton kind="link_inline" onClick={this.onCallResumeClick}>
2022-05-04 17:16:38 +02:00
{sub}
</AccessibleButton>
),
},
);
} else if (isLocalOnHold) {
onHoldText = _t("voip|call_held", {
peerName: call.getOpponentMember()?.name,
2022-05-04 17:16:38 +02:00
});
}
2021-03-07 08:13:35 +01:00
holdTransferContent = <div className="mx_LegacyCallView_status">{onHoldText}</div>;
2021-03-07 08:13:35 +01:00
}
2022-05-04 17:16:38 +02:00
return (
<div className={containerClasses} onMouseMove={this.onMouseMove}>
<div
className="mx_LegacyCallView_holdBackground"
style={{ backgroundImage: "url(" + backgroundAvatarUrl + ")" }}
/>
2022-05-04 17:16:38 +02:00
{holdTransferContent}
</div>
);
} else if (call.noIncomingFeeds()) {
return (
<div className="mx_LegacyCallView_content" onMouseMove={this.onMouseMove}>
<div className="mx_LegacyCallView_avatarsContainer">
2021-06-12 08:15:26 +02:00
<div
className="mx_LegacyCallView_avatarContainer"
style={{ width: avatarSize, height: avatarSize }}
2021-06-12 08:15:26 +02:00
>
<RoomAvatar room={callRoom} size={avatarSize} />
2021-06-12 08:15:26 +02:00
</div>
</div>
<div className="mx_LegacyCallView_status">{_t("voip|connecting")}</div>
2022-05-04 17:16:38 +02:00
{secondaryFeedElement}
</div>
);
} else if (pipMode) {
// We've already checked that we have feeds so we cast away the optional when passing the feed
2022-05-04 17:16:38 +02:00
return (
<div className="mx_LegacyCallView_content" onMouseMove={this.onMouseMove}>
<VideoFeed
feed={primaryFeed as CallFeed}
call={call}
pipMode={pipMode}
onResize={onResize}
primary={true}
/>
2022-05-04 17:16:38 +02:00
</div>
);
} else if (secondaryFeed) {
return (
<div className="mx_LegacyCallView_content" onMouseMove={this.onMouseMove}>
<VideoFeed
feed={primaryFeed as CallFeed}
call={call}
pipMode={pipMode}
onResize={onResize}
primary={true}
/>
2022-05-04 17:16:38 +02:00
{secondaryFeedElement}
2020-11-26 14:35:09 +00:00
</div>
2021-06-12 08:15:26 +02:00
);
2021-03-07 08:13:35 +01:00
} else {
2022-05-04 17:16:38 +02:00
return (
<div className="mx_LegacyCallView_content" onMouseMove={this.onMouseMove}>
<VideoFeed
feed={primaryFeed as CallFeed}
call={call}
pipMode={pipMode}
onResize={onResize}
primary={true}
/>
{sidebarShown && (
<LegacyCallViewSidebar feeds={sidebarFeeds} call={call} pipMode={Boolean(pipMode)} />
)}
2021-06-12 08:15:26 +02:00
</div>
);
2020-07-06 22:42:46 +01:00
}
2022-05-04 17:16:38 +02:00
}
public render(): React.ReactNode {
2022-05-04 17:16:38 +02:00
const { call, secondaryCall, pipMode, showApps, onMouseDownOnHeader } = this.props;
const { sidebarShown, sidebarFeeds } = this.state;
const client = MatrixClientPeg.safeGet();
const callRoomId = LegacyCallHandler.instance.roomIdForCall(call);
const secondaryCallRoomId = LegacyCallHandler.instance.roomIdForCall(secondaryCall);
const callRoom = callRoomId ? client.getRoom(callRoomId) : null;
if (!callRoom) return null;
const secCallRoom = secondaryCallRoomId ? client.getRoom(secondaryCallRoomId) : null;
2020-07-06 22:42:46 +01:00
const callViewClasses = classNames({
mx_LegacyCallView: true,
mx_LegacyCallView_pip: pipMode,
mx_LegacyCallView_large: !pipMode,
mx_LegacyCallView_sidebar: sidebarShown && sidebarFeeds.length !== 0 && !pipMode,
mx_LegacyCallView_belowWidget: showApps, // css to correct the margins if the call is below the AppsDrawer.
});
2020-11-12 18:09:56 +00:00
return (
<div className={callViewClasses}>
<LegacyCallViewHeader
2022-05-04 17:16:38 +02:00
onPipMouseDown={onMouseDownOnHeader}
pipMode={pipMode}
callRooms={[callRoom, secCallRoom]}
onMaximize={this.onMaximizeClick}
/>
<div className="mx_LegacyCallView_content_wrapper" ref={this.contentWrapperRef}>
2022-05-04 17:16:38 +02:00
{this.renderToast()}
{this.renderContent()}
{this.renderCallControls()}
2022-12-12 12:24:14 +01:00
</div>
2022-05-04 17:16:38 +02:00
</div>
2020-07-06 22:42:46 +01:00
);
}
}