import React, { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { batch, connect } 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, getParticipantById } from '../../../base/participants/functions'; import { IParticipant } from '../../../base/participants/types'; import Popover from '../../../base/popover/components/Popover.web'; import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions'; import Button from '../../../base/ui/components/web/Button'; import ConnectionIndicatorContent from '../../../connection-indicator/components/web/ConnectionIndicatorContent'; import { THUMBNAIL_TYPE } from '../../../filmstrip/constants'; import { renderConnectionStatus } from '../../actions.web'; import FakeParticipantContextMenu from './FakeParticipantContextMenu'; import ParticipantContextMenu from './ParticipantContextMenu'; import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton'; /** * The type of the React {@code Component} props of * {@link RemoteVideoMenuTriggerButton}. */ interface IProps { /** * Whether the remote video context menu is disabled. */ _disabled: Boolean; /** * Shared video local participant owner. */ _localVideoOwner?: boolean; /** * The position relative to the trigger the remote menu should display * from. */ _menuPosition: string; /** * Participant reference. */ _participant: IParticipant; /** * The ID for the participant on which the remote video menu will act. */ _participantDisplayName: string; /** * The current state of the participant's remote control session. */ _remoteControlState?: number; /** * Whether the popover should render the Connection Info stats. */ _showConnectionInfo: Boolean; /** * Whether or not the button should be visible. */ buttonVisible: boolean; /** * The redux dispatch function. */ dispatch: IStore['dispatch']; /** * Hides popover. */ hidePopover?: Function; /** * The ID for the participant on which the remote video menu will act. */ participantID: string; /** * 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', marginRight: '4px', marginBottom: '4px' } }; }); const RemoteVideoMenuTriggerButton = ({ _disabled, _localVideoOwner, _menuPosition, _participant, _participantDisplayName, _remoteControlState, _showConnectionInfo, buttonVisible, dispatch, hidePopover, participantID, popoverVisible, showPopover }: IProps) => { const { classes } = useStyles(); const { t } = useTranslation(); const _onPopoverOpen = useCallback(() => { showPopover?.(); dispatch(setParticipantContextMenuOpen(true)); }, []); const _onPopoverClose = useCallback(() => { hidePopover?.(); batch(() => { dispatch(setParticipantContextMenuOpen(false)); dispatch(renderConnectionStatus(false)); }); }, []); // eslint-disable-next-line react/no-multi-comp const _renderRemoteVideoMenu = () => { const props = { className: classes.contextMenu, onSelect: _onPopoverClose, participant: _participant, thumbnailMenu: true }; if (_participant?.fakeParticipant) { return ( ); } return ( ); }; let content; if (_showConnectionInfo) { content = ; } else if (!_disabled) { content = _renderRemoteVideoMenu(); } if (!content) { return null; } const username = _participantDisplayName; return ( {buttonVisible && !_disabled && ( !isMobileBrowser() &&