mirror of
https://github.com/vector-im/element-call.git
synced 2026-11-19 09:32:29 +08:00
260 lines
7.8 KiB
TypeScript
260 lines
7.8 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
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 LogoMark from "../icons/LogoMark.svg?react";
|
|
import LogoType from "../icons/LogoType.svg?react";
|
|
import {
|
|
EndCallButton,
|
|
ShareScreenButton,
|
|
SettingsButton,
|
|
ReactionToggleButton,
|
|
LoudspeakerButton,
|
|
SettingsIconButton,
|
|
type ReactionData,
|
|
} from "../button";
|
|
import styles from "./CallFooter.module.css";
|
|
import { type Behavior } from "../state/Behavior";
|
|
import { type ViewModel } from "../state/ViewModel";
|
|
import { useBehavior } from "../useBehavior";
|
|
import { type LayoutSwitchViewModel } from "../state/LayoutSwitchViewModel";
|
|
import { LayoutSwitch } from "../room/LayoutSwitch";
|
|
import { type MediaMenuViewModel } from "./MediaMenuViewModel";
|
|
import { MediaMenuButton } from "./MediaMenuButton";
|
|
|
|
export interface AudioOutputSwitcher {
|
|
targetOutput: string;
|
|
switch: () => void;
|
|
}
|
|
|
|
/**
|
|
* The Snapshot combines all fields required to populate the view.
|
|
*
|
|
* It is a combination of Actions and State.
|
|
* All Actions and State will be wrappen in behaviors.
|
|
* This has the advantage, that actions can mutate.
|
|
* (example: a device gets disconnected, the swicht action is not possible anymore, the actions becomes undefined)
|
|
* With it being reactive we can use the existance of the action to update the rendering without
|
|
* requiring additional state.
|
|
*
|
|
* Comment: It might not make sense to seperate the two interfaces. Hence the seperation
|
|
* just happens on the syntax level with the `type = ... & ...` notation.
|
|
*/
|
|
export type FooterSnapshot = FooterActions & FooterState;
|
|
export interface FooterActions {
|
|
toggleScreenSharing: (() => void) | undefined;
|
|
/** Also controls if the settings button is visible */
|
|
openSettings: (() => void) | undefined;
|
|
/** Also controls if the hangup button is visible */
|
|
hangup: (() => void) | undefined;
|
|
}
|
|
|
|
// we do not use any ? optional properties so that the vm type is including all fields.
|
|
export interface FooterState {
|
|
audioMenuVm: MediaMenuViewModel;
|
|
cameraMenuVm: MediaMenuViewModel;
|
|
showFooter: boolean;
|
|
|
|
/* This is needed for WindowMode = "flat" */
|
|
hideControls: boolean;
|
|
/** The footer should be used as an overlay.
|
|
* (Over the Call Grid) This saves spaces on small screens. */
|
|
asOverlay: boolean;
|
|
showModals: boolean;
|
|
|
|
buttonSize: "md" | "lg";
|
|
showLogo: boolean;
|
|
|
|
/** Also controls if the layout switch is visible */
|
|
layoutSwitchVm: LayoutSwitchViewModel | null;
|
|
|
|
sharingScreen: boolean;
|
|
|
|
/** Also controls if the audio output button is visible */
|
|
audioOutputSwitcher: AudioOutputSwitcher | undefined;
|
|
|
|
reactionIdentifier: string | undefined;
|
|
reactionData: ReactionData | undefined;
|
|
|
|
// debug stuff
|
|
debugTileLayout: boolean;
|
|
tileStoreGeneration: number | undefined;
|
|
}
|
|
|
|
export interface FooterProps {
|
|
className?: string;
|
|
ref?: Ref<HTMLDivElement>;
|
|
children?: JSX.Element | JSX.Element[] | false;
|
|
vm: ViewModel<FooterSnapshot>;
|
|
}
|
|
|
|
export const CallFooter: FC<FooterProps> = ({
|
|
className,
|
|
ref,
|
|
children,
|
|
vm,
|
|
}) => {
|
|
const asOverlay = useBehavior(vm.asOverlay$);
|
|
const showFooter = useBehavior(vm.showFooter$);
|
|
const hideControls = useBehavior(vm.hideControls$);
|
|
const showModals = useBehavior(vm.showModals$);
|
|
const layoutSwitchVm = useBehavior(vm.layoutSwitchVm$);
|
|
const audioMenuVm = useBehavior(vm.audioMenuVm$);
|
|
const cameraMenuVm = useBehavior(vm.cameraMenuVm$);
|
|
const openSettings = useBehavior(vm.openSettings$);
|
|
const sharingScreen = useBehavior(vm.sharingScreen$);
|
|
const toggleScreenSharing = useBehavior(vm.toggleScreenSharing$);
|
|
const reactionIdentifier = useBehavior(vm.reactionIdentifier$);
|
|
const reactionData = useBehavior(vm.reactionData$);
|
|
const audioOutputSwitcher = useBehavior(vm.audioOutputSwitcher$);
|
|
const hangup = useBehavior(vm.hangup$);
|
|
const debugTileLayout = useBehavior(vm.debugTileLayout$);
|
|
const buttonSize = useBehavior(vm.buttonSize$);
|
|
const showLogo = useBehavior(vm.showLogo$);
|
|
|
|
const buttons: JSX.Element[] = [];
|
|
|
|
if (openSettings !== undefined) {
|
|
// 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}
|
|
data-testid="settings-bottom-center"
|
|
/>,
|
|
);
|
|
}
|
|
|
|
buttons.push(
|
|
<MediaMenuButton
|
|
key="audio"
|
|
kind="audio"
|
|
vm={audioMenuVm}
|
|
size={buttonSize}
|
|
/>,
|
|
<MediaMenuButton
|
|
key="video"
|
|
kind="video"
|
|
vm={cameraMenuVm}
|
|
size={buttonSize}
|
|
/>,
|
|
);
|
|
|
|
if (toggleScreenSharing !== undefined) {
|
|
buttons.push(
|
|
<ShareScreenButton
|
|
size={buttonSize}
|
|
key="share_screen"
|
|
className={styles.shareScreen}
|
|
enabled={sharingScreen ?? false}
|
|
onClick={toggleScreenSharing}
|
|
data-testid="incall_screenshare"
|
|
/>,
|
|
);
|
|
}
|
|
|
|
// Reaction button contains a pretty large menu, so treat it like a modal
|
|
if (reactionIdentifier && reactionData && showModals) {
|
|
buttons.push(
|
|
<ReactionToggleButton
|
|
size={buttonSize}
|
|
reactionData={reactionData}
|
|
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(() => {
|
|
if (audioOutputSwitcher === undefined) return null;
|
|
return (
|
|
<LoudspeakerButton
|
|
size={buttonSize}
|
|
onClick={() => audioOutputSwitcher.switch()}
|
|
loudspeakerModeEnabled={audioOutputSwitcher.targetOutput === "earpiece"}
|
|
/>
|
|
);
|
|
}, [audioOutputSwitcher, buttonSize]);
|
|
|
|
if (audioOutputButton) buttons.push(audioOutputButton);
|
|
|
|
if (hangup)
|
|
buttons.push(
|
|
<EndCallButton
|
|
size={buttonSize}
|
|
key="end_call"
|
|
onClick={hangup}
|
|
data-testid="incall_leave"
|
|
/>,
|
|
);
|
|
|
|
const logoDebugContainer = (
|
|
<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 ? (
|
|
<TilesDebugInfo generation$={vm.tileStoreGeneration$} />
|
|
) : undefined}
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
data-testid="footer-container"
|
|
className={classNames(className, styles.footer, {
|
|
[styles.overlay]: asOverlay,
|
|
[styles.hidden]: !showFooter,
|
|
})}
|
|
>
|
|
<div className={styles.settingsLogoContainer}>
|
|
{openSettings !== undefined && (
|
|
<SettingsIconButton
|
|
key="settings"
|
|
kind="secondary"
|
|
showForScreenWidth="wide"
|
|
onClick={openSettings}
|
|
data-testid="settings-bottom-left"
|
|
/>
|
|
)}
|
|
{children}
|
|
{(showLogo || debugTileLayout) && logoDebugContainer}
|
|
</div>
|
|
{!hideControls && <div className={styles.buttons}>{buttons}</div>}
|
|
{!hideControls && layoutSwitchVm && (
|
|
<LayoutSwitch vm={layoutSwitchVm} className={styles.layout} />
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
interface TilesDebugInfoProps {
|
|
generation$: Behavior<number | undefined>;
|
|
}
|
|
|
|
// Isolated in its own component since the layout generation updates frequently
|
|
// and we can avoid re-rendering the footer this way
|
|
const TilesDebugInfo: FC<TilesDebugInfoProps> = ({ generation$ }) => {
|
|
const generation = useBehavior(generation$);
|
|
return `Tiles generation: ${generation}`;
|
|
};
|