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.

MeetingParticipantContextMenu.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { isToolbarButtonEnabled } from '../../base/config/functions.web';
  4. import { openDialog } from '../../base/dialog';
  5. import { translate } from '../../base/i18n';
  6. import {
  7. IconCloseCircle,
  8. IconCrown,
  9. IconMessage,
  10. IconMicDisabled,
  11. IconMuteEveryoneElse,
  12. IconVideoOff
  13. } from '../../base/icons';
  14. import {
  15. getParticipantByIdOrUndefined,
  16. isLocalParticipantModerator,
  17. isParticipantModerator
  18. } from '../../base/participants';
  19. import { connect } from '../../base/redux';
  20. import { isParticipantAudioMuted, isParticipantVideoMuted } from '../../base/tracks';
  21. import { openChat } from '../../chat/actions';
  22. import { GrantModeratorDialog, KickRemoteParticipantDialog, MuteEveryoneDialog } from '../../video-menu';
  23. import MuteRemoteParticipantsVideoDialog from '../../video-menu/components/web/MuteRemoteParticipantsVideoDialog';
  24. import { getComputedOuterHeight } from '../functions';
  25. import {
  26. ContextMenu,
  27. ContextMenuIcon,
  28. ContextMenuItem,
  29. ContextMenuItemGroup,
  30. ignoredChildClassName
  31. } from './styled';
  32. type Props = {
  33. /**
  34. * True if the local participant is moderator and false otherwise.
  35. */
  36. _isLocalModerator: boolean,
  37. /**
  38. * True if the chat button is enabled and false otherwise.
  39. */
  40. _isChatButtonEnabled: boolean,
  41. /**
  42. * True if the participant is moderator and false otherwise.
  43. */
  44. _isParticipantModerator: boolean,
  45. /**
  46. * True if the participant is video muted and false otherwise.
  47. */
  48. _isParticipantVideoMuted: boolean,
  49. /**
  50. * True if the participant is audio muted and false otherwise.
  51. */
  52. _isParticipantAudioMuted: boolean,
  53. /**
  54. * Participant reference
  55. */
  56. _participant: Object,
  57. /**
  58. * The dispatch function from redux.
  59. */
  60. dispatch: Function,
  61. /**
  62. * Callback used to open a confirmation dialog for audio muting.
  63. */
  64. muteAudio: Function,
  65. /**
  66. * Target elements against which positioning calculations are made
  67. */
  68. offsetTarget: HTMLElement,
  69. /**
  70. * Callback for the mouse entering the component
  71. */
  72. onEnter: Function,
  73. /**
  74. * Callback for the mouse leaving the component
  75. */
  76. onLeave: Function,
  77. /**
  78. * Callback for making a selection in the menu
  79. */
  80. onSelect: Function,
  81. /**
  82. * The ID of the participant.
  83. */
  84. participantID: string,
  85. /**
  86. * The translate function.
  87. */
  88. t: Function
  89. };
  90. type State = {
  91. /**
  92. * If true the context menu will be hidden.
  93. */
  94. isHidden: boolean
  95. };
  96. /**
  97. * Implements the MeetingParticipantContextMenu component.
  98. */
  99. class MeetingParticipantContextMenu extends Component<Props, State> {
  100. /**
  101. * Reference to the context menu container div.
  102. */
  103. _containerRef: Object;
  104. /**
  105. * Creates new instance of MeetingParticipantContextMenu.
  106. *
  107. * @param {Props} props - The props.
  108. */
  109. constructor(props: Props) {
  110. super(props);
  111. this.state = {
  112. isHidden: true
  113. };
  114. this._containerRef = React.createRef();
  115. this._onGrantModerator = this._onGrantModerator.bind(this);
  116. this._onKick = this._onKick.bind(this);
  117. this._onMuteEveryoneElse = this._onMuteEveryoneElse.bind(this);
  118. this._onMuteVideo = this._onMuteVideo.bind(this);
  119. this._onSendPrivateMessage = this._onSendPrivateMessage.bind(this);
  120. this._position = this._position.bind(this);
  121. }
  122. _onGrantModerator: () => void;
  123. /**
  124. * Grant moderator permissions.
  125. *
  126. * @returns {void}
  127. */
  128. _onGrantModerator() {
  129. const { _participant, dispatch } = this.props;
  130. dispatch(openDialog(GrantModeratorDialog, {
  131. participantID: _participant?.id
  132. }));
  133. }
  134. _onKick: () => void;
  135. /**
  136. * Kicks the participant.
  137. *
  138. * @returns {void}
  139. */
  140. _onKick() {
  141. const { _participant, dispatch } = this.props;
  142. dispatch(openDialog(KickRemoteParticipantDialog, {
  143. participantID: _participant?.id
  144. }));
  145. }
  146. _onMuteEveryoneElse: () => void;
  147. /**
  148. * Mutes everyone else.
  149. *
  150. * @returns {void}
  151. */
  152. _onMuteEveryoneElse() {
  153. const { _participant, dispatch } = this.props;
  154. dispatch(openDialog(MuteEveryoneDialog, {
  155. exclude: [ _participant?.id ]
  156. }));
  157. }
  158. _onMuteVideo: () => void;
  159. /**
  160. * Mutes the video of the selected participant.
  161. *
  162. * @returns {void}
  163. */
  164. _onMuteVideo() {
  165. const { _participant, dispatch } = this.props;
  166. dispatch(openDialog(MuteRemoteParticipantsVideoDialog, {
  167. participantID: _participant?.id
  168. }));
  169. }
  170. _onSendPrivateMessage: () => void;
  171. /**
  172. * Sends private message.
  173. *
  174. * @returns {void}
  175. */
  176. _onSendPrivateMessage() {
  177. const { _participant, dispatch } = this.props;
  178. dispatch(openChat(_participant));
  179. }
  180. _position: () => void;
  181. /**
  182. * Positions the context menu.
  183. *
  184. * @returns {void}
  185. */
  186. _position() {
  187. const { _participant, offsetTarget } = this.props;
  188. if (_participant
  189. && this._containerRef.current
  190. && offsetTarget?.offsetParent
  191. && offsetTarget.offsetParent instanceof HTMLElement
  192. ) {
  193. const { current: container } = this._containerRef;
  194. const { offsetTop, offsetParent: { offsetHeight, scrollTop } } = offsetTarget;
  195. const outerHeight = getComputedOuterHeight(container);
  196. container.style.top = offsetTop + outerHeight > offsetHeight + scrollTop
  197. ? offsetTop - outerHeight
  198. : offsetTop;
  199. this.setState({ isHidden: false });
  200. } else {
  201. this.setState({ isHidden: true });
  202. }
  203. }
  204. /**
  205. * Implements React Component's componentDidMount.
  206. *
  207. * @inheritdoc
  208. * @returns {void}
  209. */
  210. componentDidMount() {
  211. this._position();
  212. }
  213. /**
  214. * Implements React Component's componentDidUpdate.
  215. *
  216. * @inheritdoc
  217. */
  218. componentDidUpdate(prevProps: Props) {
  219. if (prevProps.offsetTarget !== this.props.offsetTarget || prevProps._participant !== this.props._participant) {
  220. this._position();
  221. }
  222. }
  223. /**
  224. * Implements React's {@link Component#render()}.
  225. *
  226. * @inheritdoc
  227. * @returns {ReactElement}
  228. */
  229. render() {
  230. const {
  231. _isLocalModerator,
  232. _isChatButtonEnabled,
  233. _isParticipantModerator,
  234. _isParticipantVideoMuted,
  235. _isParticipantAudioMuted,
  236. _participant,
  237. onEnter,
  238. onLeave,
  239. onSelect,
  240. muteAudio,
  241. t
  242. } = this.props;
  243. if (!_participant) {
  244. return null;
  245. }
  246. return (
  247. <ContextMenu
  248. className = { ignoredChildClassName }
  249. innerRef = { this._containerRef }
  250. isHidden = { this.state.isHidden }
  251. onClick = { onSelect }
  252. onMouseEnter = { onEnter }
  253. onMouseLeave = { onLeave }>
  254. <ContextMenuItemGroup>
  255. {
  256. _isLocalModerator && (
  257. <>
  258. {
  259. !_isParticipantAudioMuted
  260. && <ContextMenuItem onClick = { muteAudio(_participant) }>
  261. <ContextMenuIcon src = { IconMicDisabled } />
  262. <span>{t('dialog.muteParticipantButton')}</span>
  263. </ContextMenuItem>
  264. }
  265. <ContextMenuItem onClick = { this._onMuteEveryoneElse }>
  266. <ContextMenuIcon src = { IconMuteEveryoneElse } />
  267. <span>{t('toolbar.accessibilityLabel.muteEveryoneElse')}</span>
  268. </ContextMenuItem>
  269. </>
  270. )
  271. }
  272. {
  273. _isLocalModerator && (
  274. _isParticipantVideoMuted || (
  275. <ContextMenuItem onClick = { this._onMuteVideo }>
  276. <ContextMenuIcon src = { IconVideoOff } />
  277. <span>{t('participantsPane.actions.stopVideo')}</span>
  278. </ContextMenuItem>
  279. )
  280. )
  281. }
  282. </ContextMenuItemGroup>
  283. <ContextMenuItemGroup>
  284. {
  285. _isLocalModerator && (
  286. <>
  287. {
  288. !_isParticipantModerator && (
  289. <ContextMenuItem onClick = { this._onGrantModerator }>
  290. <ContextMenuIcon src = { IconCrown } />
  291. <span>{t('toolbar.accessibilityLabel.grantModerator')}</span>
  292. </ContextMenuItem>
  293. )
  294. }
  295. <ContextMenuItem onClick = { this._onKick }>
  296. <ContextMenuIcon src = { IconCloseCircle } />
  297. <span>{ t('videothumbnail.kick') }</span>
  298. </ContextMenuItem>
  299. </>
  300. )
  301. }
  302. {
  303. _isChatButtonEnabled && (
  304. <ContextMenuItem onClick = { this._onSendPrivateMessage }>
  305. <ContextMenuIcon src = { IconMessage } />
  306. <span>{t('toolbar.accessibilityLabel.privateMessage')}</span>
  307. </ContextMenuItem>
  308. )
  309. }
  310. </ContextMenuItemGroup>
  311. </ContextMenu>
  312. );
  313. }
  314. }
  315. /**
  316. * Maps (parts of) the redux state to the associated props for this component.
  317. *
  318. * @param {Object} state - The Redux state.
  319. * @param {Object} ownProps - The own props of the component.
  320. * @private
  321. * @returns {Props}
  322. */
  323. function _mapStateToProps(state, ownProps): Object {
  324. const { participantID } = ownProps;
  325. const participant = getParticipantByIdOrUndefined(state, participantID);
  326. const _isLocalModerator = isLocalParticipantModerator(state);
  327. const _isChatButtonEnabled = isToolbarButtonEnabled('chat', state);
  328. const _isParticipantVideoMuted = isParticipantVideoMuted(participant, state);
  329. const _isParticipantAudioMuted = isParticipantAudioMuted(participant, state);
  330. const _isParticipantModerator = isParticipantModerator(participant);
  331. return {
  332. _isLocalModerator,
  333. _isChatButtonEnabled,
  334. _isParticipantModerator,
  335. _isParticipantVideoMuted,
  336. _isParticipantAudioMuted,
  337. _participant: participant
  338. };
  339. }
  340. export default translate(connect(_mapStateToProps)(MeetingParticipantContextMenu));