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

248 lines
6.6 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";
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,
} from "../button";
2026-04-14 13:25:33 +02:00
import styles from "./CallFooter.module.css";
2026-04-09 15:49:09 +02:00
import { LayoutToggle } from "../room/LayoutToggle";
import {
type CallViewModel,
type GridMode,
} from "../state/CallViewModel/CallViewModel";
import { useAppBarSecondaryButton } from "../AppBar";
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-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;
audioEnabled?: boolean;
/** Also controls if the audioMute button is disabled */
2026-04-09 15:49:09 +02:00
toggleAudio?: () => void;
2026-04-14 13:25:33 +02:00
videoEnabled?: boolean;
/** Also controls if the videoMute button is disabled */
2026-04-09 15:49:09 +02:00
toggleVideo?: () => void;
2026-04-14 13:25:33 +02:00
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;
reactionData?: Pick<CallViewModel, "handsRaised$" | "reactions$">;
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 ? "sm" : "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 and the one without `forButtonsBar` in the `settingsLogoContainer` will be visible.
buttons.push(
<SettingsButton
forButtonsBar
key="settings"
showForScreenWidth="narrow"
onClick={openSettings}
/>,
);
}
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={
reactionData ??
({
handsRaised$: new BehaviorSubject({}),
reactions$: new BehaviorSubject({}),
} as Pick<CallViewModel, "handsRaised$" | "reactions$">)
}
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-09 15:49:09 +02:00
isEarpieceTarget={audioOutputSwitcher.targetOutput === "earpiece"}
/>
);
}, [audioOutputSwitcher, buttonSize]);
if (audioOutputButton) buttons.push(audioOutputButton);
useAppBarSecondaryButton(
<SettingsButton key="settings" onClick={openSettings} />,
2026-04-09 15:49:09 +02:00
);
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 && (
<SettingsButton
key="settings"
showForScreenWidth="wide"
onClick={openSettings}
/>
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-09 15:49:09 +02:00
<LayoutToggle
className={styles.layout}
2026-04-14 13:25:33 +02:00
layout={layoutMode}
setLayout={setLayoutMode}
2026-04-09 15:49:09 +02:00
/>
)}
</div>
);
};