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

ParticipantContextMenu.tsx 11KB

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