Files
element-call/src/components/CallFooter.tsx
T

256 lines
6.9 KiB
TypeScript
Raw Normal View History

2026-04-09 15:49:09 +02:00
/*
Copyright 2026 Element Creations Ltd.
2026-04-09 15:49:09 +02:00
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
*/
import { type FC, type JSX, type Ref, useMemo } from "react";
import classNames from "classnames";
2026-04-14 13:25:33 +02:00
import { BehaviorSubject } from "rxjs";
import { Switch } from "@vector-im/compound-web";
import { t } from "i18next";
import {
SpotlightIcon,
GridIcon,
} from "@vector-im/compound-design-tokens/assets/web/icons";
2026-04-09 15:49:09 +02:00
import LogoMark from "../icons/LogoMark.svg?react";
import LogoType from "../icons/LogoType.svg?react";
import {
EndCallButton,
MicButton,
VideoButton,
ShareScreenButton,
SettingsButton,
ReactionToggleButton,
LoudspeakerButton,
SettingsIconButton,
2026-04-15 13:06:47 +02:00
type ReactionData,
2026-04-09 15:49:09 +02:00
} from "../button";
2026-04-14 13:25:33 +02:00
import styles from "./CallFooter.module.css";
2026-04-15 13:06:47 +02:00
import { type GridMode } from "../state/CallViewModel/CallViewModel";
2026-04-09 15:49:09 +02:00
export interface AudioOutputSwitcher {
targetOutput: string;
switch: () => void;
}
2026-04-14 13:25:33 +02:00
export interface FooterProps {
2026-04-09 15:49:09 +02:00
ref?: Ref<HTMLDivElement>;
2026-04-14 13:25:33 +02:00
/** Children will only be visible if the component is wider than 5*/
children?: JSX.Element | JSX.Element[] | false;
2026-04-15 16:41:19 +02:00
audioEnabled: boolean;
/** Also controls if the audioMute button is disabled */
toggleAudio: (() => void) | undefined;
videoEnabled: boolean;
/** Also controls if the videoMute button is disabled */
toggleVideo: (() => void) | undefined;
2026-04-09 15:49:09 +02:00
/* This is needed for WindowMode = "flat" */
2026-04-14 13:25:33 +02:00
hideControls?: boolean;
/** hide the entire footer*/
hidden?: boolean;
/** Pip controls buttonSize and hides: settings button, layout switcher and logo */
2026-04-14 13:25:33 +02:00
asPip?: boolean;
/** The footer should be used as an overlay.
* (Over the Call Grid) This saves spaces on small screens.*/
asOverlay?: boolean;
layoutMode?: GridMode;
/** Also controls if the layout button is visible */
setLayoutMode?: (mode: GridMode) => void;
sharingScreen?: boolean;
2026-04-09 15:49:09 +02:00
toggleScreenSharing?: () => void;
2026-04-14 13:25:33 +02:00
/** Also controls if the audio button is visible */
audioOutputSwitcher?: AudioOutputSwitcher;
/** Also controls if the settings button is visible */
openSettings?: () => void;
/** Also controls if the hangup button is visible */
hangup?: () => void;
reactionIdentifier?: string;
2026-04-15 13:06:47 +02:00
reactionData?: ReactionData;
2026-04-14 13:25:33 +02:00
hideLogo?: boolean;
// debug stuff
debugTileLayout?: boolean;
tileStoreGeneration?: number;
2026-04-09 15:49:09 +02:00
}
2026-04-14 13:25:33 +02:00
export const CallFooter: FC<FooterProps> = ({
2026-04-09 15:49:09 +02:00
ref,
2026-04-14 13:25:33 +02:00
children,
2026-04-09 15:49:09 +02:00
asOverlay,
2026-04-14 13:25:33 +02:00
hidden,
hideControls,
hideLogo,
2026-04-09 15:49:09 +02:00
asPip,
2026-04-14 13:25:33 +02:00
layoutMode,
setLayoutMode,
2026-04-09 15:49:09 +02:00
openSettings,
audioEnabled,
videoEnabled,
toggleAudio,
toggleVideo,
sharingScreen,
toggleScreenSharing,
reactionIdentifier,
reactionData,
audioOutputSwitcher,
hangup,
debugTileLayout,
tileStoreGeneration,
}) => {
const buttons: JSX.Element[] = [];
const buttonSize = asPip ? "md" : "lg";
2026-04-14 13:25:33 +02:00
const showSettingsButton =
openSettings !== undefined && !asPip && !hideControls;
const showLayoutSwitcher = !asPip && !hideControls;
const showLogoDebugContainer = !asPip || (!hideLogo && !debugTileLayout);
const showLogo = !hideLogo && !asPip;
if (showSettingsButton) {
// add the settings button to the center group of buttons, so it will be visible on small screens.
// On larger screens, it will be hidden SettingsIconButton the one with `showForScreenWidth = "wide"` in the `settingsLogoContainer` will be visible.
buttons.push(
<SettingsButton
key="settings"
showForScreenWidth="narrow"
onClick={openSettings}
2026-04-15 15:51:21 +02:00
data-testid="settings-bottom-center"
/>,
);
}
2026-04-09 15:49:09 +02:00
buttons.push(
<MicButton
size={buttonSize}
key="audio"
2026-04-14 13:25:33 +02:00
enabled={audioEnabled ?? false}
onClick={toggleAudio}
2026-04-09 17:12:21 +02:00
disabled={toggleAudio === undefined}
2026-04-09 15:49:09 +02:00
data-testid="incall_mute"
/>,
<VideoButton
size={buttonSize}
key="video"
2026-04-14 13:25:33 +02:00
enabled={videoEnabled ?? false}
onClick={toggleVideo}
2026-04-09 17:12:21 +02:00
disabled={toggleVideo === undefined}
2026-04-09 15:49:09 +02:00
data-testid="incall_videomute"
/>,
);
2026-04-14 13:25:33 +02:00
if (toggleScreenSharing !== undefined) {
2026-04-09 15:49:09 +02:00
buttons.push(
<ShareScreenButton
size={buttonSize}
key="share_screen"
className={styles.shareScreen}
2026-04-14 13:25:33 +02:00
enabled={sharingScreen ?? false}
2026-04-09 15:49:09 +02:00
onClick={toggleScreenSharing}
data-testid="incall_screenshare"
/>,
);
}
if (reactionIdentifier && reactionData) {
2026-04-09 15:49:09 +02:00
buttons.push(
<ReactionToggleButton
size={buttonSize}
2026-04-14 13:25:33 +02:00
reactionData={
2026-04-15 13:06:47 +02:00
reactionData ?? {
2026-04-14 13:25:33 +02:00
handsRaised$: new BehaviorSubject({}),
reactions$: new BehaviorSubject({}),
2026-04-15 13:06:47 +02:00
}
2026-04-14 13:25:33 +02:00
}
2026-04-09 15:49:09 +02:00
key="raise_hand"
className={styles.raiseHand}
identifier={reactionIdentifier}
/>,
);
}
// In this PR we just move the button to the bottom bar. We do not yet update its appearance
const audioOutputButton = useMemo(() => {
2026-04-14 13:25:33 +02:00
if (audioOutputSwitcher === undefined) return null;
2026-04-09 15:49:09 +02:00
return (
<LoudspeakerButton
size={buttonSize}
2026-04-09 17:12:21 +02:00
onClick={() => audioOutputSwitcher.switch()}
2026-04-15 16:41:19 +02:00
loudspeakerModeEnabled={audioOutputSwitcher.targetOutput === "earpiece"}
2026-04-09 15:49:09 +02:00
/>
);
}, [audioOutputSwitcher, buttonSize]);
if (audioOutputButton) buttons.push(audioOutputButton);
2026-04-14 13:25:33 +02:00
if (hangup)
buttons.push(
<EndCallButton
size={buttonSize}
key="end_call"
onClick={hangup}
data-testid="incall_leave"
/>,
);
2026-04-09 15:49:09 +02:00
const logoDebugContainer = (
2026-04-09 15:49:09 +02:00
<div className={styles.logo}>
{showLogo && (
<>
<LogoMark width={24} height={24} aria-hidden />
<LogoType
width={80}
height={11}
aria-label={import.meta.env.VITE_PRODUCT_NAME || "Element Call"}
/>
</>
)}
{debugTileLayout ? `Tiles generation: ${tileStoreGeneration}` : undefined}
</div>
);
return (
<div
ref={ref}
className={classNames(styles.footer, {
[styles.overlay]: asOverlay,
2026-04-14 13:25:33 +02:00
[styles.hidden]: hidden,
2026-04-09 15:49:09 +02:00
})}
>
<div className={styles.settingsLogoContainer}>
{showSettingsButton && (
<SettingsIconButton
key="settings"
kind="secondary"
showForScreenWidth="wide"
onClick={openSettings}
2026-04-15 15:51:21 +02:00
data-testid="settings-bottom-left"
/>
2026-04-09 15:49:09 +02:00
)}
2026-04-14 13:25:33 +02:00
{children}
{showLogoDebugContainer && logoDebugContainer}
2026-04-09 15:49:09 +02:00
</div>
2026-04-14 13:25:33 +02:00
{!hideControls && <div className={styles.buttons}>{buttons}</div>}
{setLayoutMode && layoutMode && showLayoutSwitcher && (
2026-04-24 11:54:24 +01:00
<Switch<"spotlight", "grid">
aria-label={t("layout_switch_label")}
leftLabel={t("layout_spotlight_label")}
leftValue="spotlight"
leftIcon={SpotlightIcon}
rightLabel={t("layout_grid_label")}
rightValue="grid"
rightIcon={GridIcon}
2026-04-09 15:49:09 +02:00
className={styles.layout}
value={layoutMode}
onChange={setLayoutMode}
2026-04-09 15:49:09 +02:00
/>
)}
</div>
);
};