Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ParticipantContextMenu.tsx 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /* eslint-disable lines-around-comment */
  2. import React, { useCallback } 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. // @ts-ignore
  9. import { Avatar } from '../../../base/avatar';
  10. import { isIosMobileBrowser, isMobileBrowser } from '../../../base/environment/utils';
  11. import { MEDIA_TYPE } from '../../../base/media/constants';
  12. import { PARTICIPANT_ROLE } from '../../../base/participants/constants';
  13. import { getLocalParticipant } from '../../../base/participants/functions';
  14. import { IParticipant } from '../../../base/participants/types';
  15. import { isParticipantAudioMuted } from '../../../base/tracks/functions';
  16. import ContextMenu from '../../../base/ui/components/web/ContextMenu';
  17. import ContextMenuItemGroup from '../../../base/ui/components/web/ContextMenuItemGroup';
  18. import { getBreakoutRooms, getCurrentRoomId, isInBreakoutRoom } from '../../../breakout-rooms/functions';
  19. import { displayVerification } from '../../../e2ee/functions';
  20. import { setVolume } from '../../../filmstrip/actions.web';
  21. import { isStageFilmstripAvailable } from '../../../filmstrip/functions.web';
  22. import { isForceMuted } from '../../../participants-pane/functions';
  23. // @ts-ignore
  24. import { requestRemoteControl, stopController } from '../../../remote-control';
  25. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  26. import CustomOptionButton from './CustomOptionButton';
  27. // @ts-ignore
  28. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  29. // @ts-ignore
  30. import SendToRoomButton from './SendToRoomButton';
  31. import VerifyParticipantButton from './VerifyParticipantButton';
  32. import {
  33. AskToUnmuteButton,
  34. ConnectionStatusButton,
  35. GrantModeratorButton,
  36. KickButton,
  37. MuteButton,
  38. MuteEveryoneElseButton,
  39. MuteEveryoneElsesVideoButton,
  40. MuteVideoButton,
  41. PrivateMessageMenuButton,
  42. RemoteControlButton,
  43. TogglePinToStageButton,
  44. VolumeSlider
  45. // @ts-ignore
  46. } from './';
  47. /* eslint-enable lines-around-comment */
  48. interface IProps {
  49. /**
  50. * Class name for the context menu.
  51. */
  52. className?: string;
  53. /**
  54. * Closes a drawer if open.
  55. */
  56. closeDrawer?: () => void;
  57. /**
  58. * The participant for which the drawer is open.
  59. * It contains the displayName & participantID.
  60. */
  61. drawerParticipant?: {
  62. displayName: string;
  63. participantID: string;
  64. };
  65. /**
  66. * Target elements against which positioning calculations are made.
  67. */
  68. offsetTarget?: HTMLElement;
  69. /**
  70. * Callback for the mouse entering the component.
  71. */
  72. onEnter?: (e?: React.MouseEvent) => void;
  73. /**
  74. * Callback for the mouse leaving the component.
  75. */
  76. onLeave?: (e?: React.MouseEvent) => void;
  77. /**
  78. * Callback for making a selection in the menu.
  79. */
  80. onSelect: (value?: boolean | React.MouseEvent) => void;
  81. /**
  82. * Participant reference.
  83. */
  84. participant: IParticipant;
  85. /**
  86. * The current state of the participant's remote control session.
  87. */
  88. remoteControlState?: number;
  89. /**
  90. * Whether or not the menu is displayed in the thumbnail remote video menu.
  91. */
  92. thumbnailMenu?: boolean;
  93. }
  94. const useStyles = makeStyles()(theme => {
  95. return {
  96. text: {
  97. color: theme.palette.text02,
  98. padding: '10px 16px',
  99. height: '40px',
  100. overflow: 'hidden',
  101. display: 'flex',
  102. alignItems: 'center',
  103. boxSizing: 'border-box'
  104. }
  105. };
  106. });
  107. const ParticipantContextMenu = ({
  108. className,
  109. closeDrawer,
  110. drawerParticipant,
  111. offsetTarget,
  112. onEnter,
  113. onLeave,
  114. onSelect,
  115. participant,
  116. remoteControlState,
  117. thumbnailMenu
  118. }: IProps) => {
  119. const dispatch = useDispatch();
  120. const { t } = useTranslation();
  121. const { classes: styles } = useStyles();
  122. const localParticipant = useSelector(getLocalParticipant);
  123. const _isModerator = Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR);
  124. const _isAudioForceMuted = useSelector<IReduxState>(state =>
  125. isForceMuted(participant, MEDIA_TYPE.AUDIO, state));
  126. const _isVideoForceMuted = useSelector<IReduxState>(state =>
  127. isForceMuted(participant, MEDIA_TYPE.VIDEO, state));
  128. const _isAudioMuted = useSelector((state: IReduxState) => isParticipantAudioMuted(participant, state));
  129. const _overflowDrawer: boolean = useSelector(showOverflowDrawer);
  130. const { remoteVideoMenu = {}, disableRemoteMute, startSilent, customParticipantMenuButtons }
  131. = useSelector((state: IReduxState) => state['features/base/config']);
  132. const { disableKick, disableGrantModerator, disablePrivateChat } = remoteVideoMenu;
  133. const { participantsVolume } = useSelector((state: IReduxState) => state['features/filmstrip']);
  134. const _volume = (participant?.local ?? true ? undefined
  135. : participant?.id ? participantsVolume[participant?.id] : undefined) ?? 1;
  136. const isBreakoutRoom = useSelector(isInBreakoutRoom);
  137. const isModerationSupported = useSelector((state: IReduxState) => isAvModerationSupported()(state));
  138. const stageFilmstrip = useSelector(isStageFilmstripAvailable);
  139. const shouldDisplayVerification = useSelector((state: IReduxState) => displayVerification(state, participant?.id));
  140. const _currentRoomId = useSelector(getCurrentRoomId);
  141. const _rooms: Array<{ id: string; }> = Object.values(useSelector(getBreakoutRooms));
  142. const _onVolumeChange = useCallback(value => {
  143. dispatch(setVolume(participant.id, value));
  144. }, [ setVolume, dispatch ]);
  145. const clickHandler = useCallback(() => onSelect(true), [ onSelect ]);
  146. const _getCurrentParticipantId = useCallback(() => {
  147. const drawer = _overflowDrawer && !thumbnailMenu;
  148. return (drawer ? drawerParticipant?.participantID : participant?.id) ?? '';
  149. }
  150. , [ thumbnailMenu, _overflowDrawer, drawerParticipant, participant ]);
  151. const buttons: JSX.Element[] = [];
  152. const buttons2: JSX.Element[] = [];
  153. const showVolumeSlider = !startSilent
  154. && !isIosMobileBrowser()
  155. && (_overflowDrawer || thumbnailMenu)
  156. && typeof _volume === 'number'
  157. && !isNaN(_volume);
  158. if (_isModerator) {
  159. if ((thumbnailMenu || _overflowDrawer) && isModerationSupported && _isAudioMuted) {
  160. buttons.push(<AskToUnmuteButton
  161. isAudioForceMuted = { _isAudioForceMuted }
  162. isVideoForceMuted = { _isVideoForceMuted }
  163. key = 'ask-unmute'
  164. participantID = { _getCurrentParticipantId() } />
  165. );
  166. }
  167. if (!disableRemoteMute) {
  168. buttons.push(
  169. <MuteButton
  170. key = 'mute'
  171. participantID = { _getCurrentParticipantId() } />
  172. );
  173. buttons.push(
  174. <MuteEveryoneElseButton
  175. key = 'mute-others'
  176. participantID = { _getCurrentParticipantId() } />
  177. );
  178. buttons.push(
  179. <MuteVideoButton
  180. key = 'mute-video'
  181. participantID = { _getCurrentParticipantId() } />
  182. );
  183. buttons.push(
  184. <MuteEveryoneElsesVideoButton
  185. key = 'mute-others-video'
  186. participantID = { _getCurrentParticipantId() } />
  187. );
  188. }
  189. if (!disableGrantModerator && !isBreakoutRoom) {
  190. buttons2.push(
  191. <GrantModeratorButton
  192. key = 'grant-moderator'
  193. participantID = { _getCurrentParticipantId() } />
  194. );
  195. }
  196. if (!disableKick) {
  197. buttons2.push(
  198. <KickButton
  199. key = 'kick'
  200. participantID = { _getCurrentParticipantId() } />
  201. );
  202. }
  203. if (shouldDisplayVerification) {
  204. buttons2.push(
  205. <VerifyParticipantButton
  206. key = 'verify'
  207. participantID = { _getCurrentParticipantId() } />
  208. );
  209. }
  210. }
  211. if (stageFilmstrip) {
  212. buttons2.push(<TogglePinToStageButton
  213. key = 'pinToStage'
  214. participantID = { _getCurrentParticipantId() } />);
  215. }
  216. if (!disablePrivateChat) {
  217. buttons2.push(<PrivateMessageMenuButton
  218. key = 'privateMessage'
  219. participantID = { _getCurrentParticipantId() } />
  220. );
  221. }
  222. if (thumbnailMenu && isMobileBrowser()) {
  223. buttons2.push(
  224. <ConnectionStatusButton
  225. key = 'conn-status'
  226. participantId = { _getCurrentParticipantId() } />
  227. );
  228. }
  229. if (thumbnailMenu && remoteControlState) {
  230. let onRemoteControlToggle = null;
  231. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  232. onRemoteControlToggle = () => dispatch(stopController(true));
  233. } else if (remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  234. onRemoteControlToggle = () => dispatch(requestRemoteControl(_getCurrentParticipantId()));
  235. }
  236. buttons2.push(
  237. <RemoteControlButton
  238. key = 'remote-control'
  239. onClick = { onRemoteControlToggle }
  240. participantID = { _getCurrentParticipantId() }
  241. remoteControlState = { remoteControlState } />
  242. );
  243. }
  244. if (customParticipantMenuButtons) {
  245. customParticipantMenuButtons.forEach(
  246. ({ icon, id, text }) => {
  247. const onClick = useCallback(
  248. () => APP.API.notifyParticipantMenuButtonClicked(id, _getCurrentParticipantId()), []);
  249. buttons2.push(
  250. <CustomOptionButton
  251. icon = { icon }
  252. key = { id }
  253. onClick = { onClick }
  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. key = { room.id }
  266. onClick = { clickHandler }
  267. participantID = { _getCurrentParticipantId() }
  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;