Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ParticipantContextMenu.tsx 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. import { displayVerification } from '../../../e2ee/functions';
  20. import { setVolume } from '../../../filmstrip/actions.web';
  21. import { isStageFilmstripAvailable } from '../../../filmstrip/functions.web';
  22. import { isForceMuted } from '../../../participants-pane/functions';
  23. // @ts-ignore
  24. import { requestRemoteControl, stopController } from '../../../remote-control';
  25. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  26. // @ts-ignore
  27. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  28. // @ts-ignore
  29. import SendToRoomButton from './SendToRoomButton';
  30. import VerifyParticipantButton from './VerifyParticipantButton';
  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. /* eslint-enable lines-around-comment */
  47. interface IProps {
  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 => {
  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. }: IProps) => {
  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 shouldDisplayVerification = useSelector((state: IReduxState) => displayVerification(state, participant?.id));
  139. const _currentRoomId = useSelector(getCurrentRoomId);
  140. const _rooms: Array<{ id: string; }> = Object.values(useSelector(getBreakoutRooms));
  141. const _onVolumeChange = useCallback(value => {
  142. dispatch(setVolume(participant.id, value));
  143. }, [ setVolume, dispatch ]);
  144. const clickHandler = useCallback(() => onSelect(true), [ onSelect ]);
  145. const _getCurrentParticipantId = useCallback(() => {
  146. const drawer = _overflowDrawer && !thumbnailMenu;
  147. return (drawer ? drawerParticipant?.participantID : participant?.id) ?? '';
  148. }
  149. , [ thumbnailMenu, _overflowDrawer, drawerParticipant, participant ]);
  150. const buttons = [];
  151. const buttons2 = [];
  152. const showVolumeSlider = !startSilent
  153. && !isIosMobileBrowser()
  154. && (_overflowDrawer || thumbnailMenu)
  155. && typeof _volume === 'number'
  156. && !isNaN(_volume);
  157. if (_isModerator) {
  158. if ((thumbnailMenu || _overflowDrawer) && isModerationSupported && _isAudioMuted) {
  159. buttons.push(<AskToUnmuteButton
  160. isAudioForceMuted = { _isAudioForceMuted }
  161. isVideoForceMuted = { _isVideoForceMuted }
  162. key = 'ask-unmute'
  163. participantID = { _getCurrentParticipantId() } />
  164. );
  165. }
  166. if (!disableRemoteMute) {
  167. buttons.push(
  168. <MuteButton
  169. key = 'mute'
  170. participantID = { _getCurrentParticipantId() } />
  171. );
  172. buttons.push(
  173. <MuteEveryoneElseButton
  174. key = 'mute-others'
  175. participantID = { _getCurrentParticipantId() } />
  176. );
  177. buttons.push(
  178. <MuteVideoButton
  179. key = 'mute-video'
  180. participantID = { _getCurrentParticipantId() } />
  181. );
  182. buttons.push(
  183. <MuteEveryoneElsesVideoButton
  184. key = 'mute-others-video'
  185. participantID = { _getCurrentParticipantId() } />
  186. );
  187. }
  188. if (!disableGrantModerator && !isBreakoutRoom) {
  189. buttons2.push(
  190. <GrantModeratorButton
  191. key = 'grant-moderator'
  192. participantID = { _getCurrentParticipantId() } />
  193. );
  194. }
  195. if (!disableKick) {
  196. buttons2.push(
  197. <KickButton
  198. key = 'kick'
  199. participantID = { _getCurrentParticipantId() } />
  200. );
  201. }
  202. if (shouldDisplayVerification) {
  203. buttons2.push(
  204. <VerifyParticipantButton
  205. key = 'verify'
  206. participantID = { _getCurrentParticipantId() } />
  207. );
  208. }
  209. }
  210. if (stageFilmstrip) {
  211. buttons2.push(<TogglePinToStageButton
  212. key = 'pinToStage'
  213. participantID = { _getCurrentParticipantId() } />);
  214. }
  215. if (!disablePrivateChat) {
  216. buttons2.push(<PrivateMessageMenuButton
  217. key = 'privateMessage'
  218. participantID = { _getCurrentParticipantId() } />
  219. );
  220. }
  221. if (thumbnailMenu && isMobileBrowser()) {
  222. buttons2.push(
  223. <ConnectionStatusButton
  224. key = 'conn-status'
  225. participantId = { _getCurrentParticipantId() } />
  226. );
  227. }
  228. if (thumbnailMenu && remoteControlState) {
  229. let onRemoteControlToggle = null;
  230. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  231. onRemoteControlToggle = () => dispatch(stopController(true));
  232. } else if (remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  233. onRemoteControlToggle = () => dispatch(requestRemoteControl(_getCurrentParticipantId()));
  234. }
  235. buttons2.push(
  236. <RemoteControlButton
  237. key = 'remote-control'
  238. onClick = { onRemoteControlToggle }
  239. participantID = { _getCurrentParticipantId() }
  240. remoteControlState = { remoteControlState } />
  241. );
  242. }
  243. const breakoutRoomsButtons: any = [];
  244. if (!thumbnailMenu && _isModerator) {
  245. _rooms.forEach(room => {
  246. if (room.id !== _currentRoomId) {
  247. breakoutRoomsButtons.push(
  248. <SendToRoomButton
  249. key = { room.id }
  250. onClick = { clickHandler }
  251. participantID = { _getCurrentParticipantId() }
  252. room = { room } />
  253. );
  254. }
  255. });
  256. }
  257. return (
  258. <ContextMenu
  259. className = { className }
  260. entity = { participant }
  261. hidden = { thumbnailMenu ? false : undefined }
  262. inDrawer = { thumbnailMenu && _overflowDrawer }
  263. isDrawerOpen = { Boolean(drawerParticipant) }
  264. offsetTarget = { offsetTarget }
  265. onClick = { onSelect }
  266. onDrawerClose = { thumbnailMenu ? onSelect : closeDrawer }
  267. onMouseEnter = { onEnter }
  268. onMouseLeave = { onLeave }>
  269. {!thumbnailMenu && _overflowDrawer && drawerParticipant && <ContextMenuItemGroup
  270. actions = { [ {
  271. accessibilityLabel: drawerParticipant.displayName,
  272. customIcon: <Avatar
  273. participantId = { drawerParticipant.participantID }
  274. size = { 20 } />,
  275. text: drawerParticipant.displayName
  276. } ] } />}
  277. {buttons.length > 0 && (
  278. <ContextMenuItemGroup>
  279. {buttons}
  280. </ContextMenuItemGroup>
  281. )}
  282. <ContextMenuItemGroup>
  283. {buttons2}
  284. </ContextMenuItemGroup>
  285. {showVolumeSlider && (
  286. <ContextMenuItemGroup>
  287. <VolumeSlider
  288. initialValue = { _volume }
  289. key = 'volume-slider'
  290. onChange = { _onVolumeChange } />
  291. </ContextMenuItemGroup>
  292. )}
  293. {breakoutRoomsButtons.length > 0 && (
  294. <ContextMenuItemGroup>
  295. <div className = { styles.text }>
  296. {t('breakoutRooms.actions.sendToBreakoutRoom')}
  297. </div>
  298. {breakoutRoomsButtons}
  299. </ContextMenuItemGroup>
  300. )}
  301. </ContextMenu>
  302. );
  303. };
  304. export default ParticipantContextMenu;