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.

MeetingParticipantContextMenu.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. // @flow
  2. import { withStyles } from '@material-ui/core/styles';
  3. import React, { Component } from 'react';
  4. import { Avatar } from '../../../base/avatar';
  5. import { isToolbarButtonEnabled } from '../../../base/config/functions.web';
  6. import { openDialog } from '../../../base/dialog';
  7. import { isIosMobileBrowser } from '../../../base/environment/utils';
  8. import { translate } from '../../../base/i18n';
  9. import {
  10. IconCloseCircle,
  11. IconCrown,
  12. IconMessage,
  13. IconMicDisabled,
  14. IconMuteEveryoneElse,
  15. IconShareVideo,
  16. IconVideoOff
  17. } from '../../../base/icons';
  18. import {
  19. getLocalParticipant,
  20. getParticipantByIdOrUndefined,
  21. isLocalParticipantModerator,
  22. isParticipantModerator
  23. } from '../../../base/participants';
  24. import { connect } from '../../../base/redux';
  25. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  26. import { isParticipantAudioMuted, isParticipantVideoMuted } from '../../../base/tracks';
  27. import { openChatById } from '../../../chat/actions';
  28. import { setVolume } from '../../../filmstrip/actions.web';
  29. import { Drawer, DrawerPortal } from '../../../toolbox/components/web';
  30. import { GrantModeratorDialog, KickRemoteParticipantDialog, MuteEveryoneDialog } from '../../../video-menu';
  31. import { VolumeSlider } from '../../../video-menu/components/web';
  32. import MuteRemoteParticipantsVideoDialog from '../../../video-menu/components/web/MuteRemoteParticipantsVideoDialog';
  33. import { getComputedOuterHeight } from '../../functions';
  34. import {
  35. ContextMenu,
  36. ContextMenuIcon,
  37. ContextMenuItem,
  38. ContextMenuItemGroup,
  39. ignoredChildClassName
  40. } from './styled';
  41. type Props = {
  42. /**
  43. * True if the local participant is moderator and false otherwise.
  44. */
  45. _isLocalModerator: boolean,
  46. /**
  47. * True if the chat button is enabled and false otherwise.
  48. */
  49. _isChatButtonEnabled: boolean,
  50. /**
  51. * True if the participant is moderator and false otherwise.
  52. */
  53. _isParticipantModerator: boolean,
  54. /**
  55. * True if the participant is video muted and false otherwise.
  56. */
  57. _isParticipantVideoMuted: boolean,
  58. /**
  59. * True if the participant is audio muted and false otherwise.
  60. */
  61. _isParticipantAudioMuted: boolean,
  62. /**
  63. * Shared video local participant owner.
  64. */
  65. _localVideoOwner: boolean,
  66. /**
  67. * Participant reference
  68. */
  69. _participant: Object,
  70. /**
  71. * A value between 0 and 1 indicating the volume of the participant's
  72. * audio element.
  73. */
  74. _volume: ?number,
  75. /**
  76. * Closes a drawer if open.
  77. */
  78. closeDrawer: Function,
  79. /**
  80. * An object containing the CSS classes.
  81. */
  82. classes?: {[ key: string]: string},
  83. /**
  84. * The dispatch function from redux.
  85. */
  86. dispatch: Function,
  87. /**
  88. * The participant for which the drawer is open.
  89. * It contains the displayName & participantID.
  90. */
  91. drawerParticipant: Object,
  92. /**
  93. * Callback used to open a confirmation dialog for audio muting.
  94. */
  95. muteAudio: Function,
  96. /**
  97. * Target elements against which positioning calculations are made
  98. */
  99. offsetTarget: HTMLElement,
  100. /**
  101. * Callback for the mouse entering the component
  102. */
  103. onEnter: Function,
  104. /**
  105. * Callback for the mouse leaving the component
  106. */
  107. onLeave: Function,
  108. /**
  109. * Callback for making a selection in the menu
  110. */
  111. onSelect: Function,
  112. /**
  113. * The ID of the participant.
  114. */
  115. participantID: string,
  116. /**
  117. * True if an overflow drawer should be displayed.
  118. */
  119. overflowDrawer: boolean,
  120. /**
  121. * The translate function.
  122. */
  123. t: Function
  124. };
  125. type State = {
  126. /**
  127. * If true the context menu will be hidden.
  128. */
  129. isHidden: boolean
  130. };
  131. const styles = theme => {
  132. return {
  133. drawer: {
  134. '& > div': {
  135. ...withPixelLineHeight(theme.typography.bodyShortRegularLarge),
  136. lineHeight: '32px',
  137. '& svg': {
  138. fill: theme.palette.icon01
  139. }
  140. },
  141. '&:first-child': {
  142. marginTop: 15
  143. }
  144. }
  145. };
  146. };
  147. /**
  148. * Implements the MeetingParticipantContextMenu component.
  149. */
  150. class MeetingParticipantContextMenu extends Component<Props, State> {
  151. /**
  152. * Reference to the context menu container div.
  153. */
  154. _containerRef: Object;
  155. /**
  156. * Creates new instance of MeetingParticipantContextMenu.
  157. *
  158. * @param {Props} props - The props.
  159. */
  160. constructor(props: Props) {
  161. super(props);
  162. this.state = {
  163. isHidden: true
  164. };
  165. this._containerRef = React.createRef();
  166. this._getCurrentParticipantId = this._getCurrentParticipantId.bind(this);
  167. this._onGrantModerator = this._onGrantModerator.bind(this);
  168. this._onKick = this._onKick.bind(this);
  169. this._onMuteEveryoneElse = this._onMuteEveryoneElse.bind(this);
  170. this._onMuteVideo = this._onMuteVideo.bind(this);
  171. this._onSendPrivateMessage = this._onSendPrivateMessage.bind(this);
  172. this._position = this._position.bind(this);
  173. this._onVolumeChange = this._onVolumeChange.bind(this);
  174. }
  175. _getCurrentParticipantId: () => string;
  176. /**
  177. * Returns the participant id for the item we want to operate.
  178. *
  179. * @returns {void}
  180. */
  181. _getCurrentParticipantId() {
  182. const { _participant, drawerParticipant, overflowDrawer } = this.props;
  183. return overflowDrawer ? drawerParticipant?.participantID : _participant?.id;
  184. }
  185. _onGrantModerator: () => void;
  186. /**
  187. * Grant moderator permissions.
  188. *
  189. * @returns {void}
  190. */
  191. _onGrantModerator() {
  192. this.props.dispatch(openDialog(GrantModeratorDialog, {
  193. participantID: this._getCurrentParticipantId()
  194. }));
  195. }
  196. _onKick: () => void;
  197. /**
  198. * Kicks the participant.
  199. *
  200. * @returns {void}
  201. */
  202. _onKick() {
  203. this.props.dispatch(openDialog(KickRemoteParticipantDialog, {
  204. participantID: this._getCurrentParticipantId()
  205. }));
  206. }
  207. _onStopSharedVideo: () => void;
  208. /**
  209. * Stops shared video.
  210. *
  211. * @returns {void}
  212. */
  213. _onStopSharedVideo() {
  214. const { dispatch } = this.props;
  215. dispatch(this._onStopSharedVideo());
  216. }
  217. _onMuteEveryoneElse: () => void;
  218. /**
  219. * Mutes everyone else.
  220. *
  221. * @returns {void}
  222. */
  223. _onMuteEveryoneElse() {
  224. this.props.dispatch(openDialog(MuteEveryoneDialog, {
  225. exclude: [ this._getCurrentParticipantId() ]
  226. }));
  227. }
  228. _onMuteVideo: () => void;
  229. /**
  230. * Mutes the video of the selected participant.
  231. *
  232. * @returns {void}
  233. */
  234. _onMuteVideo() {
  235. this.props.dispatch(openDialog(MuteRemoteParticipantsVideoDialog, {
  236. participantID: this._getCurrentParticipantId()
  237. }));
  238. }
  239. _onSendPrivateMessage: () => void;
  240. /**
  241. * Sends private message.
  242. *
  243. * @returns {void}
  244. */
  245. _onSendPrivateMessage() {
  246. const { closeDrawer, dispatch, overflowDrawer } = this.props;
  247. dispatch(openChatById(this._getCurrentParticipantId()));
  248. overflowDrawer && closeDrawer();
  249. }
  250. _position: () => void;
  251. /**
  252. * Positions the context menu.
  253. *
  254. * @returns {void}
  255. */
  256. _position() {
  257. const { _participant, offsetTarget } = this.props;
  258. if (_participant
  259. && this._containerRef.current
  260. && offsetTarget?.offsetParent
  261. && offsetTarget.offsetParent instanceof HTMLElement
  262. ) {
  263. const { current: container } = this._containerRef;
  264. const { offsetTop, offsetParent: { offsetHeight, scrollTop } } = offsetTarget;
  265. const outerHeight = getComputedOuterHeight(container);
  266. container.style.top = offsetTop + outerHeight > offsetHeight + scrollTop
  267. ? offsetTop - outerHeight
  268. : offsetTop;
  269. this.setState({ isHidden: false });
  270. } else {
  271. this.setState({ isHidden: true });
  272. }
  273. }
  274. _onVolumeChange: (number) => void;
  275. /**
  276. * Handles volume changes.
  277. *
  278. * @param {number} value - The new value for the volume.
  279. * @returns {void}
  280. */
  281. _onVolumeChange(value) {
  282. const { _participant, dispatch } = this.props;
  283. const { id } = _participant;
  284. dispatch(setVolume(id, value));
  285. }
  286. /**
  287. * Implements React Component's componentDidMount.
  288. *
  289. * @inheritdoc
  290. * @returns {void}
  291. */
  292. componentDidMount() {
  293. this._position();
  294. }
  295. /**
  296. * Implements React Component's componentDidUpdate.
  297. *
  298. * @inheritdoc
  299. */
  300. componentDidUpdate(prevProps: Props) {
  301. if (prevProps.offsetTarget !== this.props.offsetTarget || prevProps._participant !== this.props._participant) {
  302. this._position();
  303. }
  304. }
  305. /**
  306. * Implements React's {@link Component#render()}.
  307. *
  308. * @inheritdoc
  309. * @returns {ReactElement}
  310. */
  311. render() {
  312. const {
  313. _isLocalModerator,
  314. _isChatButtonEnabled,
  315. _isParticipantModerator,
  316. _isParticipantVideoMuted,
  317. _isParticipantAudioMuted,
  318. _localVideoOwner,
  319. _participant,
  320. _volume = 1,
  321. classes,
  322. closeDrawer,
  323. drawerParticipant,
  324. onEnter,
  325. onLeave,
  326. onSelect,
  327. overflowDrawer,
  328. muteAudio,
  329. t
  330. } = this.props;
  331. if (!_participant) {
  332. return null;
  333. }
  334. const showVolumeSlider = !isIosMobileBrowser()
  335. && overflowDrawer
  336. && typeof _volume === 'number'
  337. && !isNaN(_volume);
  338. const actions
  339. = _participant?.isFakeParticipant ? (
  340. <>
  341. {_localVideoOwner && (
  342. <ContextMenuItem onClick = { this._onStopSharedVideo }>
  343. <ContextMenuIcon src = { IconShareVideo } />
  344. <span>{t('toolbar.stopSharedVideo')}</span>
  345. </ContextMenuItem>
  346. )}
  347. </>
  348. ) : (
  349. <>
  350. {_isLocalModerator && (
  351. <ContextMenuItemGroup>
  352. <>
  353. {
  354. !_isParticipantAudioMuted && overflowDrawer
  355. && <ContextMenuItem onClick = { muteAudio(_participant) }>
  356. <ContextMenuIcon src = { IconMicDisabled } />
  357. <span>{t('dialog.muteParticipantButton')}</span>
  358. </ContextMenuItem>
  359. }
  360. <ContextMenuItem onClick = { this._onMuteEveryoneElse }>
  361. <ContextMenuIcon src = { IconMuteEveryoneElse } />
  362. <span>{t('toolbar.accessibilityLabel.muteEveryoneElse')}</span>
  363. </ContextMenuItem>
  364. </>
  365. {
  366. _isParticipantVideoMuted || (
  367. <ContextMenuItem onClick = { this._onMuteVideo }>
  368. <ContextMenuIcon src = { IconVideoOff } />
  369. <span>{t('participantsPane.actions.stopVideo')}</span>
  370. </ContextMenuItem>
  371. )
  372. }
  373. </ContextMenuItemGroup>
  374. )}
  375. <ContextMenuItemGroup>
  376. {
  377. _isLocalModerator && (
  378. <>
  379. {
  380. !_isParticipantModerator && (
  381. <ContextMenuItem onClick = { this._onGrantModerator }>
  382. <ContextMenuIcon src = { IconCrown } />
  383. <span>{t('toolbar.accessibilityLabel.grantModerator')}</span>
  384. </ContextMenuItem>
  385. )
  386. }
  387. <ContextMenuItem onClick = { this._onKick }>
  388. <ContextMenuIcon src = { IconCloseCircle } />
  389. <span>{ t('videothumbnail.kick') }</span>
  390. </ContextMenuItem>
  391. </>
  392. )
  393. }
  394. {
  395. _isChatButtonEnabled && (
  396. <ContextMenuItem onClick = { this._onSendPrivateMessage }>
  397. <ContextMenuIcon src = { IconMessage } />
  398. <span>{t('toolbar.accessibilityLabel.privateMessage')}</span>
  399. </ContextMenuItem>
  400. )
  401. }
  402. </ContextMenuItemGroup>
  403. { showVolumeSlider
  404. && <ContextMenuItemGroup>
  405. <VolumeSlider
  406. initialValue = { _volume }
  407. key = 'volume-slider'
  408. onChange = { this._onVolumeChange } />
  409. </ContextMenuItemGroup>
  410. }
  411. </>
  412. );
  413. return (
  414. <>
  415. { !overflowDrawer
  416. && <ContextMenu
  417. className = { ignoredChildClassName }
  418. innerRef = { this._containerRef }
  419. isHidden = { this.state.isHidden }
  420. onClick = { onSelect }
  421. onMouseEnter = { onEnter }
  422. onMouseLeave = { onLeave }>
  423. { actions }
  424. </ContextMenu>}
  425. <DrawerPortal>
  426. <Drawer
  427. isOpen = { drawerParticipant && overflowDrawer }
  428. onClose = { closeDrawer }>
  429. <div className = { classes && classes.drawer }>
  430. <ContextMenuItemGroup>
  431. <ContextMenuItem>
  432. <Avatar
  433. participantId = { drawerParticipant && drawerParticipant.participantID }
  434. size = { 20 } />
  435. <span>{ drawerParticipant && drawerParticipant.displayName }</span>
  436. </ContextMenuItem>
  437. </ContextMenuItemGroup>
  438. { actions }
  439. </div>
  440. </Drawer>
  441. </DrawerPortal>
  442. </>
  443. );
  444. }
  445. }
  446. /**
  447. * Maps (parts of) the redux state to the associated props for this component.
  448. *
  449. * @param {Object} state - The Redux state.
  450. * @param {Object} ownProps - The own props of the component.
  451. * @private
  452. * @returns {Props}
  453. */
  454. function _mapStateToProps(state, ownProps): Object {
  455. const { participantID, overflowDrawer, drawerParticipant } = ownProps;
  456. const { ownerId } = state['features/shared-video'];
  457. const localParticipantId = getLocalParticipant(state).id;
  458. const participant = getParticipantByIdOrUndefined(state,
  459. overflowDrawer ? drawerParticipant?.participantID : participantID);
  460. const _isLocalModerator = isLocalParticipantModerator(state);
  461. const _isChatButtonEnabled = isToolbarButtonEnabled('chat', state);
  462. const _isParticipantVideoMuted = isParticipantVideoMuted(participant, state);
  463. const _isParticipantAudioMuted = isParticipantAudioMuted(participant, state);
  464. const _isParticipantModerator = isParticipantModerator(participant);
  465. const { participantsVolume } = state['features/filmstrip'];
  466. const id = participant?.id;
  467. const isLocal = participant?.local ?? true;
  468. return {
  469. _isLocalModerator,
  470. _isChatButtonEnabled,
  471. _isParticipantModerator,
  472. _isParticipantVideoMuted,
  473. _isParticipantAudioMuted,
  474. _localVideoOwner: Boolean(ownerId === localParticipantId),
  475. _participant: participant,
  476. _volume: isLocal ? undefined : id ? participantsVolume[id] : undefined
  477. };
  478. }
  479. export default withStyles(styles)(translate(connect(_mapStateToProps)(MeetingParticipantContextMenu)));