You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ParticipantContextMenu.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. // @flow
  2. import { makeStyles } from '@material-ui/styles';
  3. import React, { useCallback } from 'react';
  4. import { useTranslation } from 'react-i18next';
  5. import { useDispatch, useSelector } from 'react-redux';
  6. import { isSupported as isAvModerationSupported } from '../../../av-moderation/functions';
  7. import { Avatar } from '../../../base/avatar';
  8. import ContextMenu from '../../../base/components/context-menu/ContextMenu';
  9. import ContextMenuItemGroup from '../../../base/components/context-menu/ContextMenuItemGroup';
  10. import { isIosMobileBrowser, isMobileBrowser } from '../../../base/environment/utils';
  11. import { IconShareVideo } from '../../../base/icons';
  12. import { MEDIA_TYPE } from '../../../base/media';
  13. import { getLocalParticipant, PARTICIPANT_ROLE } from '../../../base/participants';
  14. import { isParticipantAudioMuted } from '../../../base/tracks';
  15. import { getBreakoutRooms, getCurrentRoomId, isInBreakoutRoom } from '../../../breakout-rooms/functions';
  16. import { setVolume } from '../../../filmstrip/actions.web';
  17. import { isForceMuted } from '../../../participants-pane/functions';
  18. import { requestRemoteControl, stopController } from '../../../remote-control';
  19. import { stopSharedVideo } from '../../../shared-video/actions.any';
  20. import { showOverflowDrawer } from '../../../toolbox/functions.web';
  21. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  22. import SendToRoomButton from './SendToRoomButton';
  23. import {
  24. AskToUnmuteButton,
  25. ConnectionStatusButton,
  26. GrantModeratorButton,
  27. MuteButton,
  28. MuteEveryoneElseButton,
  29. MuteEveryoneElsesVideoButton,
  30. MuteVideoButton,
  31. KickButton,
  32. PrivateMessageMenuButton,
  33. RemoteControlButton,
  34. VolumeSlider
  35. } from './';
  36. type Props = {
  37. /**
  38. * Class name for the context menu.
  39. */
  40. className?: string,
  41. /**
  42. * Closes a drawer if open.
  43. */
  44. closeDrawer?: Function,
  45. /**
  46. * The participant for which the drawer is open.
  47. * It contains the displayName & participantID.
  48. */
  49. drawerParticipant?: Object,
  50. /**
  51. * Shared video local participant owner.
  52. */
  53. localVideoOwner?: boolean,
  54. /**
  55. * Target elements against which positioning calculations are made.
  56. */
  57. offsetTarget?: HTMLElement,
  58. /**
  59. * Callback for the mouse entering the component.
  60. */
  61. onEnter?: Function,
  62. /**
  63. * Callback for the mouse leaving the component.
  64. */
  65. onLeave?: Function,
  66. /**
  67. * Callback for making a selection in the menu.
  68. */
  69. onSelect: Function,
  70. /**
  71. * Participant reference.
  72. */
  73. participant: Object,
  74. /**
  75. * The current state of the participant's remote control session.
  76. */
  77. remoteControlState?: number,
  78. /**
  79. * Whether or not the menu is displayed in the thumbnail remote video menu.
  80. */
  81. thumbnailMenu: ?boolean
  82. }
  83. const useStyles = makeStyles(theme => {
  84. return {
  85. text: {
  86. color: theme.palette.text02,
  87. padding: '10px 16px',
  88. height: '40px',
  89. overflow: 'hidden',
  90. display: 'flex',
  91. alignItems: 'center',
  92. boxSizing: 'border-box'
  93. }
  94. };
  95. });
  96. const ParticipantContextMenu = ({
  97. className,
  98. closeDrawer,
  99. drawerParticipant,
  100. localVideoOwner,
  101. offsetTarget,
  102. onEnter,
  103. onLeave,
  104. onSelect,
  105. participant,
  106. remoteControlState,
  107. thumbnailMenu
  108. }: Props) => {
  109. const dispatch = useDispatch();
  110. const { t } = useTranslation();
  111. const styles = useStyles();
  112. const localParticipant = useSelector(getLocalParticipant);
  113. const _isModerator = Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR);
  114. const _isAudioForceMuted = useSelector(state =>
  115. isForceMuted(participant, MEDIA_TYPE.AUDIO, state));
  116. const _isVideoForceMuted = useSelector(state =>
  117. isForceMuted(participant, MEDIA_TYPE.VIDEO, state));
  118. const _isAudioMuted = useSelector(state => isParticipantAudioMuted(participant, state));
  119. const _overflowDrawer = useSelector(showOverflowDrawer);
  120. const { remoteVideoMenu = {}, disableRemoteMute, startSilent }
  121. = useSelector(state => state['features/base/config']);
  122. const { disableKick, disableGrantModerator, disablePrivateChat } = remoteVideoMenu;
  123. const { participantsVolume } = useSelector(state => state['features/filmstrip']);
  124. const _volume = (participant?.local ?? true ? undefined
  125. : participant?.id ? participantsVolume[participant?.id] : undefined) ?? 1;
  126. const isBreakoutRoom = useSelector(isInBreakoutRoom);
  127. const isModerationSupported = useSelector(isAvModerationSupported());
  128. const _currentRoomId = useSelector(getCurrentRoomId);
  129. const _rooms = Object.values(useSelector(getBreakoutRooms));
  130. const _onVolumeChange = useCallback(value => {
  131. dispatch(setVolume(participant.id, value));
  132. }, [ setVolume, dispatch ]);
  133. const clickHandler = useCallback(() => onSelect(true), [ onSelect ]);
  134. const _onStopSharedVideo = useCallback(() => {
  135. clickHandler();
  136. dispatch(stopSharedVideo());
  137. }, [ stopSharedVideo ]);
  138. const _getCurrentParticipantId = useCallback(() => {
  139. const drawer = _overflowDrawer && !thumbnailMenu;
  140. return (drawer ? drawerParticipant?.participantID : participant?.id) ?? '';
  141. }
  142. , [ thumbnailMenu, _overflowDrawer, drawerParticipant, participant ]);
  143. const buttons = [];
  144. const buttons2 = [];
  145. const showVolumeSlider = !startSilent
  146. && !isIosMobileBrowser()
  147. && (_overflowDrawer || thumbnailMenu)
  148. && typeof _volume === 'number'
  149. && !isNaN(_volume);
  150. const fakeParticipantActions = [ {
  151. accessibilityLabel: t('toolbar.stopSharedVideo'),
  152. icon: IconShareVideo,
  153. onClick: _onStopSharedVideo,
  154. text: t('toolbar.stopSharedVideo')
  155. } ];
  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 (!disablePrivateChat) {
  203. buttons2.push(<PrivateMessageMenuButton
  204. key = 'privateMessage'
  205. participantID = { _getCurrentParticipantId() } />
  206. );
  207. }
  208. if (thumbnailMenu && isMobileBrowser()) {
  209. buttons2.push(
  210. <ConnectionStatusButton
  211. key = 'conn-status'
  212. participantId = { _getCurrentParticipantId() } />
  213. );
  214. }
  215. if (thumbnailMenu && remoteControlState) {
  216. let onRemoteControlToggle = null;
  217. if (remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  218. onRemoteControlToggle = () => dispatch(stopController(true));
  219. } else if (remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  220. onRemoteControlToggle = () => dispatch(requestRemoteControl(_getCurrentParticipantId()));
  221. }
  222. buttons2.push(
  223. <RemoteControlButton
  224. key = 'remote-control'
  225. onClick = { onRemoteControlToggle }
  226. participantID = { _getCurrentParticipantId() }
  227. remoteControlState = { remoteControlState } />
  228. );
  229. }
  230. const breakoutRoomsButtons = [];
  231. if (!thumbnailMenu && _isModerator) {
  232. _rooms.forEach((room: Object) => {
  233. if (room.id !== _currentRoomId) {
  234. breakoutRoomsButtons.push(
  235. <SendToRoomButton
  236. key = { room.id }
  237. onClick = { clickHandler }
  238. participantID = { _getCurrentParticipantId() }
  239. room = { room } />
  240. );
  241. }
  242. });
  243. }
  244. return (
  245. <ContextMenu
  246. className = { className }
  247. entity = { participant }
  248. hidden = { thumbnailMenu ? false : undefined }
  249. inDrawer = { thumbnailMenu && _overflowDrawer }
  250. isDrawerOpen = { drawerParticipant }
  251. offsetTarget = { offsetTarget }
  252. onClick = { onSelect }
  253. onDrawerClose = { thumbnailMenu ? onSelect : closeDrawer }
  254. onMouseEnter = { onEnter }
  255. onMouseLeave = { onLeave }>
  256. {!thumbnailMenu && _overflowDrawer && drawerParticipant && <ContextMenuItemGroup
  257. actions = { [ {
  258. accessibilityLabel: drawerParticipant.displayName,
  259. customIcon: <Avatar
  260. participantId = { drawerParticipant.participantID }
  261. size = { 20 } />,
  262. text: drawerParticipant.displayName
  263. } ] } />}
  264. {participant?.isFakeParticipant ? localVideoOwner && (
  265. <ContextMenuItemGroup
  266. actions = { fakeParticipantActions } />
  267. ) : (
  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. </>
  294. )}
  295. </ContextMenu>
  296. );
  297. };
  298. export default ParticipantContextMenu;