You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ParticipantContextMenu.tsx 14KB

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