Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ParticipantContextMenu.tsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. import React, { useCallback, useMemo } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IReduxState, IStore } from '../../../app/types';
  6. import { isSupported as isAvModerationSupported } from '../../../av-moderation/functions';
  7. import Avatar from '../../../base/avatar/components/Avatar';
  8. import { getButtonNotifyMode, getParticipantMenuButtonsWithNotifyClick } from '../../../base/config/functions.web';
  9. import { isIosMobileBrowser, isMobileBrowser } from '../../../base/environment/utils';
  10. import { MEDIA_TYPE } from '../../../base/media/constants';
  11. import { PARTICIPANT_ROLE } from '../../../base/participants/constants';
  12. import { getLocalParticipant } from '../../../base/participants/functions';
  13. import { IParticipant } from '../../../base/participants/types';
  14. import { isParticipantAudioMuted, isParticipantVideoMuted } from '../../../base/tracks/functions.any';
  15. import ContextMenu from '../../../base/ui/components/web/ContextMenu';
  16. import ContextMenuItemGroup from '../../../base/ui/components/web/ContextMenuItemGroup';
  17. import { getBreakoutRooms, getCurrentRoomId, isInBreakoutRoom } from '../../../breakout-rooms/functions';
  18. import { IRoom } from '../../../breakout-rooms/types';
  19. import { displayVerification } from '../../../e2ee/functions';
  20. import { setVolume } from '../../../filmstrip/actions.web';
  21. import { isStageFilmstripAvailable } from '../../../filmstrip/functions.web';
  22. import { QUICK_ACTION_BUTTON } from '../../../participants-pane/constants';
  23. import { getQuickActionButtonType, isForceMuted } from '../../../participants-pane/functions';
  24. import { requestRemoteControl, stopController } from '../../../remote-control/actions';
  25. import { NOTIFY_CLICK_MODE } from '../../../toolbox/constants';
  26. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  27. import { iAmVisitor } from '../../../visitors/functions';
  28. import { PARTICIPANT_MENU_BUTTONS as BUTTONS } from '../../constants';
  29. import AskToUnmuteButton from './AskToUnmuteButton';
  30. import ConnectionStatusButton from './ConnectionStatusButton';
  31. import CustomOptionButton from './CustomOptionButton';
  32. import GrantModeratorButton from './GrantModeratorButton';
  33. import KickButton from './KickButton';
  34. import MuteButton from './MuteButton';
  35. import MuteEveryoneElseButton from './MuteEveryoneElseButton';
  36. import MuteEveryoneElsesVideoButton from './MuteEveryoneElsesVideoButton';
  37. import MuteVideoButton from './MuteVideoButton';
  38. import PrivateMessageMenuButton from './PrivateMessageMenuButton';
  39. import RemoteControlButton, { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  40. import SendToRoomButton from './SendToRoomButton';
  41. import TogglePinToStageButton from './TogglePinToStageButton';
  42. import VerifyParticipantButton from './VerifyParticipantButton';
  43. import VolumeSlider from './VolumeSlider';
  44. interface IProps {
  45. /**
  46. * Class name for the context menu.
  47. */
  48. className?: string;
  49. /**
  50. * Closes a drawer if open.
  51. */
  52. closeDrawer?: () => void;
  53. /**
  54. * The participant for which the drawer is open.
  55. * It contains the displayName & participantID.
  56. */
  57. drawerParticipant?: {
  58. displayName: string;
  59. participantID: string;
  60. };
  61. /**
  62. * Target elements against which positioning calculations are made.
  63. */
  64. offsetTarget?: HTMLElement;
  65. /**
  66. * Callback for the mouse entering the component.
  67. */
  68. onEnter?: (e?: React.MouseEvent) => void;
  69. /**
  70. * Callback for the mouse leaving the component.
  71. */
  72. onLeave?: (e?: React.MouseEvent) => void;
  73. /**
  74. * Callback for making a selection in the menu.
  75. */
  76. onSelect: (value?: boolean | React.MouseEvent) => void;
  77. /**
  78. * Participant reference.
  79. */
  80. participant: IParticipant;
  81. /**
  82. * The current state of the participant's remote control session.
  83. */
  84. remoteControlState?: number;
  85. /**
  86. * Whether or not the menu is displayed in the thumbnail remote video menu.
  87. */
  88. thumbnailMenu?: boolean;
  89. }
  90. const useStyles = makeStyles()(theme => {
  91. return {
  92. text: {
  93. color: theme.palette.text02,
  94. padding: '10px 16px',
  95. height: '40px',
  96. overflow: 'hidden',
  97. display: 'flex',
  98. alignItems: 'center',
  99. boxSizing: 'border-box'
  100. }
  101. };
  102. });
  103. const ParticipantContextMenu = ({
  104. className,
  105. closeDrawer,
  106. drawerParticipant,
  107. offsetTarget,
  108. onEnter,
  109. onLeave,
  110. onSelect,
  111. participant,
  112. remoteControlState,
  113. thumbnailMenu
  114. }: IProps) => {
  115. const dispatch: IStore['dispatch'] = useDispatch();
  116. const { t } = useTranslation();
  117. const { classes: styles } = useStyles();
  118. const localParticipant = useSelector(getLocalParticipant);
  119. const _isModerator = Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR);
  120. const _isVideoForceMuted = useSelector<IReduxState>(state =>
  121. isForceMuted(participant, MEDIA_TYPE.VIDEO, state));
  122. const _isAudioMuted = useSelector((state: IReduxState) => isParticipantAudioMuted(participant, state));
  123. const _isVideoMuted = useSelector((state: IReduxState) => isParticipantVideoMuted(participant, state));
  124. const _overflowDrawer: boolean = useSelector(showOverflowDrawer);
  125. const { remoteVideoMenu = {}, disableRemoteMute, startSilent, customParticipantMenuButtons }
  126. = useSelector((state: IReduxState) => state['features/base/config']);
  127. const visitorsMode = useSelector((state: IReduxState) => iAmVisitor(state));
  128. const { disableKick, disableGrantModerator, disablePrivateChat } = remoteVideoMenu;
  129. const { participantsVolume } = useSelector((state: IReduxState) => state['features/filmstrip']);
  130. const _volume = (participant?.local ?? true ? undefined
  131. : participant?.id ? participantsVolume[participant?.id] : undefined) ?? 1;
  132. const isBreakoutRoom = useSelector(isInBreakoutRoom);
  133. const isModerationSupported = useSelector((state: IReduxState) => isAvModerationSupported()(state));
  134. const stageFilmstrip = useSelector(isStageFilmstripAvailable);
  135. const shouldDisplayVerification = useSelector((state: IReduxState) => displayVerification(state, participant?.id));
  136. const buttonsWithNotifyClick = useSelector(getParticipantMenuButtonsWithNotifyClick);
  137. const _currentRoomId = useSelector(getCurrentRoomId);
  138. const _rooms: IRoom[] = Object.values(useSelector(getBreakoutRooms));
  139. const _onVolumeChange = useCallback(value => {
  140. dispatch(setVolume(participant.id, value));
  141. }, [ setVolume, dispatch ]);
  142. const _getCurrentParticipantId = useCallback(() => {
  143. const drawer = _overflowDrawer && !thumbnailMenu;
  144. return (drawer ? drawerParticipant?.participantID : participant?.id) ?? '';
  145. }
  146. , [ thumbnailMenu, _overflowDrawer, drawerParticipant, participant ]);
  147. const notifyClick = useCallback(
  148. (buttonKey: string) => {
  149. const notifyMode = getButtonNotifyMode(buttonKey, buttonsWithNotifyClick);
  150. if (!notifyMode) {
  151. return;
  152. }
  153. APP.API.notifyParticipantMenuButtonClicked(
  154. buttonKey,
  155. _getCurrentParticipantId(),
  156. notifyMode === NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY
  157. );
  158. }, [ buttonsWithNotifyClick, getButtonNotifyMode, _getCurrentParticipantId ]);
  159. const onBreakoutRoomButtonClick = useCallback(() => {
  160. onSelect(true);
  161. }, [ onSelect ]);
  162. const isClickedFromParticipantPane = useMemo(
  163. () => !_overflowDrawer && !thumbnailMenu,
  164. [ _overflowDrawer, thumbnailMenu ]);
  165. const quickActionButtonType = useSelector((state: IReduxState) =>
  166. getQuickActionButtonType(participant, _isAudioMuted, _isVideoMuted, state));
  167. const buttons: JSX.Element[] = [];
  168. const buttons2: JSX.Element[] = [];
  169. const showVolumeSlider = !startSilent
  170. && !isIosMobileBrowser()
  171. && (_overflowDrawer || thumbnailMenu)
  172. && typeof _volume === 'number'
  173. && !isNaN(_volume);
  174. const getButtonProps = useCallback((key: string) => {
  175. const notifyMode = getButtonNotifyMode(key, buttonsWithNotifyClick);
  176. const shouldNotifyClick = notifyMode !== NOTIFY_CLICK_MODE.ONLY_NOTIFY
  177. || notifyMode !== NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY;
  178. return {
  179. key,
  180. notifyMode,
  181. notifyClick: shouldNotifyClick ? () => notifyClick(key) : undefined,
  182. participantID: _getCurrentParticipantId()
  183. };
  184. }, [ _getCurrentParticipantId, buttonsWithNotifyClick, getButtonNotifyMode, notifyClick ]);
  185. if (_isModerator) {
  186. if (isModerationSupported) {
  187. if (_isAudioMuted
  188. && !(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.ASK_TO_UNMUTE)) {
  189. buttons.push(<AskToUnmuteButton
  190. { ...getButtonProps(BUTTONS.ASK_UNMUTE) }
  191. buttonType = { MEDIA_TYPE.AUDIO } />
  192. );
  193. }
  194. if (_isVideoForceMuted
  195. && !(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.ALLOW_VIDEO)) {
  196. buttons.push(<AskToUnmuteButton
  197. { ...getButtonProps(BUTTONS.ALLOW_VIDEO) }
  198. buttonType = { MEDIA_TYPE.VIDEO } />
  199. );
  200. }
  201. }
  202. if (!disableRemoteMute) {
  203. if (!(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.MUTE)) {
  204. buttons.push(<MuteButton { ...getButtonProps(BUTTONS.MUTE) } />);
  205. }
  206. buttons.push(<MuteEveryoneElseButton { ...getButtonProps(BUTTONS.MUTE_OTHERS) } />);
  207. if (!(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.STOP_VIDEO)) {
  208. buttons.push(<MuteVideoButton { ...getButtonProps(BUTTONS.MUTE_VIDEO) } />);
  209. }
  210. buttons.push(<MuteEveryoneElsesVideoButton { ...getButtonProps(BUTTONS.MUTE_OTHERS_VIDEO) } />);
  211. }
  212. if (!disableGrantModerator && !isBreakoutRoom) {
  213. buttons2.push(<GrantModeratorButton { ...getButtonProps(BUTTONS.GRANT_MODERATOR) } />);
  214. }
  215. if (!disableKick) {
  216. buttons2.push(<KickButton { ...getButtonProps(BUTTONS.KICK) } />);
  217. }
  218. if (shouldDisplayVerification) {
  219. buttons2.push(<VerifyParticipantButton { ...getButtonProps(BUTTONS.VERIFY) } />);
  220. }
  221. }
  222. if (stageFilmstrip) {
  223. buttons2.push(<TogglePinToStageButton { ...getButtonProps(BUTTONS.PIN_TO_STAGE) } />);
  224. }
  225. if (!disablePrivateChat && !visitorsMode) {
  226. buttons2.push(<PrivateMessageMenuButton { ...getButtonProps(BUTTONS.PRIVATE_MESSAGE) } />);
  227. }
  228. if (thumbnailMenu && isMobileBrowser()) {
  229. buttons2.push(<ConnectionStatusButton { ...getButtonProps(BUTTONS.CONN_STATUS) } />);
  230. }
  231. if (thumbnailMenu && remoteControlState) {
  232. const onRemoteControlToggle = useCallback(() => {
  233. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  234. dispatch(stopController(true));
  235. } else if (remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  236. dispatch(requestRemoteControl(_getCurrentParticipantId()));
  237. }
  238. }, [ dispatch, remoteControlState, stopController, requestRemoteControl ]);
  239. buttons2.push(<RemoteControlButton
  240. { ...getButtonProps(BUTTONS.REMOTE_CONTROL) }
  241. onClick = { onRemoteControlToggle }
  242. remoteControlState = { remoteControlState } />
  243. );
  244. }
  245. if (customParticipantMenuButtons) {
  246. customParticipantMenuButtons.forEach(
  247. ({ icon, id, text }) => {
  248. buttons2.push(
  249. <CustomOptionButton
  250. icon = { icon }
  251. key = { id }
  252. // eslint-disable-next-line react/jsx-no-bind
  253. onClick = { () => notifyClick(id) }
  254. text = { text } />
  255. );
  256. }
  257. );
  258. }
  259. const breakoutRoomsButtons: any = [];
  260. if (!thumbnailMenu && _isModerator) {
  261. _rooms.forEach(room => {
  262. if (room.id !== _currentRoomId) {
  263. breakoutRoomsButtons.push(
  264. <SendToRoomButton
  265. { ...getButtonProps(BUTTONS.SEND_PARTICIPANT_TO_ROOM) }
  266. key = { room.id }
  267. onClick = { onBreakoutRoomButtonClick }
  268. room = { room } />
  269. );
  270. }
  271. });
  272. }
  273. return (
  274. <ContextMenu
  275. className = { className }
  276. entity = { participant }
  277. hidden = { thumbnailMenu ? false : undefined }
  278. inDrawer = { thumbnailMenu && _overflowDrawer }
  279. isDrawerOpen = { Boolean(drawerParticipant) }
  280. offsetTarget = { offsetTarget }
  281. onClick = { onSelect }
  282. onDrawerClose = { thumbnailMenu ? onSelect : closeDrawer }
  283. onMouseEnter = { onEnter }
  284. onMouseLeave = { onLeave }>
  285. {!thumbnailMenu && _overflowDrawer && drawerParticipant && <ContextMenuItemGroup
  286. actions = { [ {
  287. accessibilityLabel: drawerParticipant.displayName,
  288. customIcon: <Avatar
  289. participantId = { drawerParticipant.participantID }
  290. size = { 20 } />,
  291. text: drawerParticipant.displayName
  292. } ] } />}
  293. {buttons.length > 0 && (
  294. <ContextMenuItemGroup>
  295. {buttons}
  296. </ContextMenuItemGroup>
  297. )}
  298. <ContextMenuItemGroup>
  299. {buttons2}
  300. </ContextMenuItemGroup>
  301. {showVolumeSlider && (
  302. <ContextMenuItemGroup>
  303. <VolumeSlider
  304. initialValue = { _volume }
  305. key = 'volume-slider'
  306. onChange = { _onVolumeChange } />
  307. </ContextMenuItemGroup>
  308. )}
  309. {breakoutRoomsButtons.length > 0 && (
  310. <ContextMenuItemGroup>
  311. <div className = { styles.text }>
  312. {t('breakoutRooms.actions.sendToBreakoutRoom')}
  313. </div>
  314. {breakoutRoomsButtons}
  315. </ContextMenuItemGroup>
  316. )}
  317. </ContextMenu>
  318. );
  319. };
  320. export default ParticipantContextMenu;