您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ParticipantContextMenu.tsx 11KB

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