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

309 lines
8.2 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";
import {
SpotlightIcon,
GridIcon,
} from "@vector-im/compound-design-tokens/assets/web/icons";
import { Switch } from "@vector-im/compound-web";
import { t } from "i18next";
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";
import {
MediaMuteAndSwitchButton,
type MenuOptions,
type ToggleOption,
} from "./MediaMuteAndSwitchButton";
import { type ViewModel, useViewModel } from "../state/ViewModel";
2026-04-09 15:49:09 +02:00
export interface AudioOutputSwitcher {
targetOutput: string;
switch: () => void;
}
export interface FooterSnapshot {
2026-04-15 16:41:19 +02:00
audioEnabled: boolean;
/** Also controls if the audioMute button is disabled */
toggleAudio: (() => void) | undefined;
2026-04-15 16:41:19 +02:00
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;
/** The footer should be used as an overlay.
* (Over the Call Grid) This saves spaces on small screens. */
2026-04-14 13:25:33 +02:00
asOverlay?: boolean;
buttonSize: "md" | "lg";
showSettingsButton?: boolean;
showLayoutSwitcher?: boolean;
showLogoDebugContainer?: boolean;
showLogo?: boolean;
2026-04-14 13:25:33 +02:00
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 output button is visible */
2026-04-14 13:25:33 +02:00
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
// debug stuff
debugTileLayout?: boolean;
tileStoreGeneration?: number;
/** Providing no options `[]` or `undefined` will imply that we dont have a audio fast switcher */
audioOptions?: MenuOptions[];
/** Providing no options `[]` or `undefined` will imply that we dont have a audio fast switcher */
videoOptions?: MenuOptions[];
selectedAudio?: string;
selectedVideo?: string;
selectAudioButtonOption?: (deviceId: string) => void;
selectVideoButtonOption?: (option: string) => void;
videoToggles?: ToggleOption[];
2026-04-09 15:49:09 +02:00
}
export interface FooterProps {
ref?: Ref<HTMLDivElement>;
children?: JSX.Element | JSX.Element[] | false;
vm: ViewModel<FooterSnapshot>;
}
export const CallFooter: FC<FooterProps> = ({ ref, children, vm }) => {
const {
asOverlay,
hideControls,
layoutMode,
setLayoutMode,
openSettings,
audioEnabled,
videoEnabled,
toggleAudio,
toggleVideo,
sharingScreen,
toggleScreenSharing,
reactionIdentifier,
reactionData,
audioOutputSwitcher,
hangup,
debugTileLayout,
tileStoreGeneration,
videoOptions,
selectedVideo,
audioOptions,
selectedAudio,
selectAudioButtonOption,
selectVideoButtonOption,
videoToggles,
buttonSize,
showSettingsButton,
showLogoDebugContainer,
showLogo,
} = useViewModel(vm);
2026-04-09 15:49:09 +02:00
const buttons: JSX.Element[] = [];
if (showSettingsButton) {
// Add the settings button to the center group so it's visible on small
// screens. On larger screens the SettingsIconButton with
// showForScreenWidth="wide" in the settingsLogoContainer is used instead.
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
if ((audioOptions?.length ?? 0) > 0) {
buttons.push(
<MediaMuteAndSwitchButton
title={"Mic Source"}
key="audio"
iconsAndLabels="audio"
enabled={audioEnabled ?? false}
onMuteClick={toggleAudio}
data-testid="incall_mute"
options={audioOptions}
selectedOption={selectedAudio}
onSelect={selectAudioButtonOption}
/>,
);
} else {
buttons.push(
<MicButton
size={buttonSize}
key="audio"
enabled={audioEnabled ?? false}
onClick={toggleAudio}
disabled={toggleAudio === undefined}
data-testid="incall_mute"
/>,
);
}
if ((videoOptions?.length ?? 0) > 0) {
buttons.push(
<MediaMuteAndSwitchButton
title={"Camera Source"}
key="video"
iconsAndLabels="video"
enabled={videoEnabled ?? false}
onMuteClick={toggleVideo}
data-testid="incall_videomute"
options={videoOptions}
toggles={videoToggles}
selectedOption={selectedVideo}
onSelect={selectVideoButtonOption}
/>,
);
} else {
buttons.push(
<VideoButton
size={buttonSize}
key="video"
enabled={videoEnabled ?? false}
onClick={toggleVideo}
disabled={toggleVideo === undefined}
data-testid="incall_videomute"
/>,
);
}
2026-04-09 15:49:09 +02:00
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}
reactionData={reactionData}
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,
})}
>
<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 && (
2026-04-24 11:54:24 +01:00
<Switch<"spotlight", "grid">
2026-04-27 14:01:04 +01:00
name="layoutMode"
2026-04-24 11:54:24 +01:00
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>
);
};