import React, { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { batch, connect, useSelector } from 'react-redux'; import { makeStyles } from 'tss-react/mui'; import { IReduxState, IStore } from '../../../app/types'; import { isMobileBrowser } from '../../../base/environment/utils'; import { IconDotsHorizontal } from '../../../base/icons/svg'; import { getLocalParticipant, getParticipantCount } from '../../../base/participants/functions'; import Popover from '../../../base/popover/components/Popover.web'; import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions'; import { getHideSelfView } from '../../../base/settings/functions.web'; import { getLocalVideoTrack } from '../../../base/tracks/functions'; import Button from '../../../base/ui/components/web/Button'; import ContextMenu from '../../../base/ui/components/web/ContextMenu'; import ContextMenuItemGroup from '../../../base/ui/components/web/ContextMenuItemGroup'; import ConnectionIndicatorContent from '../../../connection-indicator/components/web/ConnectionIndicatorContent'; import { THUMBNAIL_TYPE } from '../../../filmstrip/constants'; import { isStageFilmstripAvailable } from '../../../filmstrip/functions.web'; import { getParticipantMenuButtonsWithNotifyClick } from '../../../toolbox/functions.web'; import { NOTIFY_CLICK_MODE } from '../../../toolbox/types'; import { renderConnectionStatus } from '../../actions.web'; import { PARTICIPANT_MENU_BUTTONS as BUTTONS } from '../../constants'; import ConnectionStatusButton from './ConnectionStatusButton'; import DemoteToVisitorButton from './DemoteToVisitorButton'; import FlipLocalVideoButton from './FlipLocalVideoButton'; import HideSelfViewVideoButton from './HideSelfViewVideoButton'; import TogglePinToStageButton from './TogglePinToStageButton'; /** * The type of the React {@code Component} props of * {@link LocalVideoMenuTriggerButton}. */ interface IProps { /** * The id of the local participant. */ _localParticipantId: string; /** * The position relative to the trigger the local video menu should display * from. */ _menuPosition: string; /** * Whether to display the Popover as a drawer. */ _overflowDrawer: boolean; /** * Whether to render the connection info pane. */ _showConnectionInfo: boolean; /** * Shows/hides the local switch to visitor button. */ _showDemote: boolean; /** * Whether to render the hide self view button. */ _showHideSelfViewButton: boolean; /** * Shows/hides the local video flip button. */ _showLocalVideoFlipButton: boolean; /** * Whether to render the pin to stage button. */ _showPinToStage: boolean; /** * Whether or not the button should be visible. */ buttonVisible: boolean; /** * The redux dispatch function. */ dispatch: IStore['dispatch']; /** * Hides popover. */ hidePopover?: Function; /** * Whether the popover is visible or not. */ popoverVisible?: boolean; /** * Shows popover. */ showPopover?: Function; /** * The type of the thumbnail. */ thumbnailType: string; } const useStyles = makeStyles()(() => { return { triggerButton: { padding: '3px !important', borderRadius: '4px', '& svg': { width: '18px', height: '18px' } }, contextMenu: { position: 'relative', marginTop: 0, right: 'auto', padding: '0', minWidth: '200px' }, flipText: { marginLeft: '36px' } }; }); const LocalVideoMenuTriggerButton = ({ _localParticipantId, _menuPosition, _overflowDrawer, _showConnectionInfo, _showDemote, _showHideSelfViewButton, _showLocalVideoFlipButton, _showPinToStage, buttonVisible, dispatch, hidePopover, showPopover, popoverVisible }: IProps) => { const { classes } = useStyles(); const { t } = useTranslation(); const buttonsWithNotifyClick = useSelector(getParticipantMenuButtonsWithNotifyClick); const visitorsSupported = useSelector((state: IReduxState) => state['features/visitors'].supported); const notifyClick = useCallback( (buttonKey: string) => { const notifyMode = buttonsWithNotifyClick?.get(buttonKey); if (!notifyMode) { return; } APP.API.notifyParticipantMenuButtonClicked( buttonKey, _localParticipantId, notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY ); }, [ buttonsWithNotifyClick ]); const _onPopoverOpen = useCallback(() => { showPopover?.(); dispatch(setParticipantContextMenuOpen(true)); }, []); const _onPopoverClose = useCallback(() => { hidePopover?.(); batch(() => { dispatch(setParticipantContextMenuOpen(false)); dispatch(renderConnectionStatus(false)); }); }, []); const content = _showConnectionInfo ? : ( ); return ( isMobileBrowser() || _showLocalVideoFlipButton || _showHideSelfViewButton ? {buttonVisible && !isMobileBrowser() && (