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

ParticipantContextMenu.tsx 14KB

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