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

ParticipantContextMenu.tsx 11KB

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