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

ParticipantContextMenu.tsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. // @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, isParticipantVideoMuted } from '../../../base/tracks/functions.any';
  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 { QUICK_ACTION_BUTTON } from '../../../participants-pane/constants';
  23. import { getQuickActionButtonType, isForceMuted } from '../../../participants-pane/functions';
  24. // @ts-ignore
  25. import { requestRemoteControl, stopController } from '../../../remote-control';
  26. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  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 { 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 isClickedFromParticipantPane = useMemo(
  152. () => !_overflowDrawer && !thumbnailMenu,
  153. [ _overflowDrawer, thumbnailMenu ]);
  154. const quickActionButtonType = useSelector((state: IReduxState) =>
  155. getQuickActionButtonType(participant, _isAudioMuted, _isVideoMuted, state));
  156. const buttons: JSX.Element[] = [];
  157. const buttons2: JSX.Element[] = [];
  158. const showVolumeSlider = !startSilent
  159. && !isIosMobileBrowser()
  160. && (_overflowDrawer || thumbnailMenu)
  161. && typeof _volume === 'number'
  162. && !isNaN(_volume);
  163. if (_isModerator) {
  164. if (isModerationSupported) {
  165. if (_isAudioMuted
  166. && !(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.ASK_TO_UNMUTE)) {
  167. buttons.push(<AskToUnmuteButton
  168. buttonType = { MEDIA_TYPE.AUDIO }
  169. key = 'ask-unmute'
  170. participantID = { _getCurrentParticipantId() } />
  171. );
  172. }
  173. if (_isVideoForceMuted
  174. && !(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.ALLOW_VIDEO)) {
  175. buttons.push(<AskToUnmuteButton
  176. buttonType = { MEDIA_TYPE.VIDEO }
  177. key = 'allow-video'
  178. participantID = { _getCurrentParticipantId() } />
  179. );
  180. }
  181. }
  182. if (!disableRemoteMute) {
  183. if (!(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.MUTE)) {
  184. buttons.push(
  185. <MuteButton
  186. key = 'mute'
  187. participantID = { _getCurrentParticipantId() } />
  188. );
  189. }
  190. buttons.push(
  191. <MuteEveryoneElseButton
  192. key = 'mute-others'
  193. participantID = { _getCurrentParticipantId() } />
  194. );
  195. if (!(isClickedFromParticipantPane && quickActionButtonType === QUICK_ACTION_BUTTON.STOP_VIDEO)) {
  196. buttons.push(
  197. <MuteVideoButton
  198. key = 'mute-video'
  199. participantID = { _getCurrentParticipantId() } />
  200. );
  201. }
  202. buttons.push(
  203. <MuteEveryoneElsesVideoButton
  204. key = 'mute-others-video'
  205. participantID = { _getCurrentParticipantId() } />
  206. );
  207. }
  208. if (!disableGrantModerator && !isBreakoutRoom) {
  209. buttons2.push(
  210. <GrantModeratorButton
  211. key = 'grant-moderator'
  212. participantID = { _getCurrentParticipantId() } />
  213. );
  214. }
  215. if (!disableKick) {
  216. buttons2.push(
  217. <KickButton
  218. key = 'kick'
  219. participantID = { _getCurrentParticipantId() } />
  220. );
  221. }
  222. if (shouldDisplayVerification) {
  223. buttons2.push(
  224. <VerifyParticipantButton
  225. key = 'verify'
  226. participantID = { _getCurrentParticipantId() } />
  227. );
  228. }
  229. }
  230. if (stageFilmstrip) {
  231. buttons2.push(<TogglePinToStageButton
  232. key = 'pinToStage'
  233. participantID = { _getCurrentParticipantId() } />);
  234. }
  235. if (!disablePrivateChat) {
  236. buttons2.push(<PrivateMessageMenuButton
  237. key = 'privateMessage'
  238. participantID = { _getCurrentParticipantId() } />
  239. );
  240. }
  241. if (thumbnailMenu && isMobileBrowser()) {
  242. buttons2.push(
  243. <ConnectionStatusButton
  244. key = 'conn-status'
  245. participantId = { _getCurrentParticipantId() } />
  246. );
  247. }
  248. if (thumbnailMenu && remoteControlState) {
  249. let onRemoteControlToggle = null;
  250. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  251. onRemoteControlToggle = () => dispatch(stopController(true));
  252. } else if (remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  253. onRemoteControlToggle = () => dispatch(requestRemoteControl(_getCurrentParticipantId()));
  254. }
  255. buttons2.push(
  256. <RemoteControlButton
  257. key = 'remote-control'
  258. onClick = { onRemoteControlToggle }
  259. participantID = { _getCurrentParticipantId() }
  260. remoteControlState = { remoteControlState } />
  261. );
  262. }
  263. if (customParticipantMenuButtons) {
  264. customParticipantMenuButtons.forEach(
  265. ({ icon, id, text }) => {
  266. const onClick = useCallback(
  267. () => APP.API.notifyParticipantMenuButtonClicked(id, _getCurrentParticipantId()), []);
  268. buttons2.push(
  269. <CustomOptionButton
  270. icon = { icon }
  271. key = { id }
  272. onClick = { onClick }
  273. text = { text } />
  274. );
  275. }
  276. );
  277. }
  278. const breakoutRoomsButtons: any = [];
  279. if (!thumbnailMenu && _isModerator) {
  280. _rooms.forEach(room => {
  281. if (room.id !== _currentRoomId) {
  282. breakoutRoomsButtons.push(
  283. <SendToRoomButton
  284. key = { room.id }
  285. onClick = { clickHandler }
  286. participantID = { _getCurrentParticipantId() }
  287. room = { room } />
  288. );
  289. }
  290. });
  291. }
  292. return (
  293. <ContextMenu
  294. className = { className }
  295. entity = { participant }
  296. hidden = { thumbnailMenu ? false : undefined }
  297. inDrawer = { thumbnailMenu && _overflowDrawer }
  298. isDrawerOpen = { Boolean(drawerParticipant) }
  299. offsetTarget = { offsetTarget }
  300. onClick = { onSelect }
  301. onDrawerClose = { thumbnailMenu ? onSelect : closeDrawer }
  302. onMouseEnter = { onEnter }
  303. onMouseLeave = { onLeave }>
  304. {!thumbnailMenu && _overflowDrawer && drawerParticipant && <ContextMenuItemGroup
  305. actions = { [ {
  306. accessibilityLabel: drawerParticipant.displayName,
  307. customIcon: <Avatar
  308. participantId = { drawerParticipant.participantID }
  309. size = { 20 } />,
  310. text: drawerParticipant.displayName
  311. } ] } />}
  312. {buttons.length > 0 && (
  313. <ContextMenuItemGroup>
  314. {buttons}
  315. </ContextMenuItemGroup>
  316. )}
  317. <ContextMenuItemGroup>
  318. {buttons2}
  319. </ContextMenuItemGroup>
  320. {showVolumeSlider && (
  321. <ContextMenuItemGroup>
  322. <VolumeSlider
  323. initialValue = { _volume }
  324. key = 'volume-slider'
  325. onChange = { _onVolumeChange } />
  326. </ContextMenuItemGroup>
  327. )}
  328. {breakoutRoomsButtons.length > 0 && (
  329. <ContextMenuItemGroup>
  330. <div className = { styles.text }>
  331. {t('breakoutRooms.actions.sendToBreakoutRoom')}
  332. </div>
  333. {breakoutRoomsButtons}
  334. </ContextMenuItemGroup>
  335. )}
  336. </ContextMenu>
  337. );
  338. };
  339. export default ParticipantContextMenu;