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.

RemoteVideoMenuTriggerButton.js 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconMenuThumb } from '../../../base/icons';
  5. import { getLocalParticipant, getParticipantById, PARTICIPANT_ROLE } from '../../../base/participants';
  6. import { Popover } from '../../../base/popover';
  7. import { connect } from '../../../base/redux';
  8. import { requestRemoteControl, stopController } from '../../../remote-control';
  9. import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
  10. import MuteEveryoneElseButton from './MuteEveryoneElseButton';
  11. import MuteEveryoneElsesVideoButton from './MuteEveryoneElsesVideoButton';
  12. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  13. import {
  14. GrantModeratorButton,
  15. MuteButton,
  16. MuteVideoButton,
  17. KickButton,
  18. PrivateMessageMenuButton,
  19. RemoteControlButton,
  20. VideoMenu,
  21. VolumeSlider
  22. } from './';
  23. declare var $: Object;
  24. declare var interfaceConfig: Object;
  25. /**
  26. * The type of the React {@code Component} props of
  27. * {@link RemoteVideoMenuTriggerButton}.
  28. */
  29. type Props = {
  30. /**
  31. * Whether or not to display the kick button.
  32. */
  33. _disableKick: boolean,
  34. /**
  35. * Whether or not to display the remote mute buttons.
  36. */
  37. _disableRemoteMute: Boolean,
  38. /**
  39. * Whether or not to display the grant moderator button.
  40. */
  41. _disableGrantModerator: Boolean,
  42. /**
  43. * Whether or not the participant is a conference moderator.
  44. */
  45. _isModerator: boolean,
  46. /**
  47. * The position relative to the trigger the remote menu should display
  48. * from. Valid values are those supported by AtlasKit
  49. * {@code InlineDialog}.
  50. */
  51. _menuPosition: string,
  52. /**
  53. * Whether to display the Popover as a drawer.
  54. */
  55. _overflowDrawer: boolean,
  56. /**
  57. * The current state of the participant's remote control session.
  58. */
  59. _remoteControlState: number,
  60. /**
  61. * The redux dispatch function.
  62. */
  63. dispatch: Function,
  64. /**
  65. * A value between 0 and 1 indicating the volume of the participant's
  66. * audio element.
  67. */
  68. initialVolumeValue: ?number,
  69. /**
  70. * Callback to invoke when changing the level of the participant's
  71. * audio element.
  72. */
  73. onVolumeChange: Function,
  74. /**
  75. * The ID for the participant on which the remote video menu will act.
  76. */
  77. participantID: string,
  78. /**
  79. * The ID for the participant on which the remote video menu will act.
  80. */
  81. _participantDisplayName: string,
  82. /**
  83. * Invoked to obtain translated strings.
  84. */
  85. t: Function
  86. };
  87. /**
  88. * React {@code Component} for displaying an icon associated with opening the
  89. * the {@code VideoMenu}.
  90. *
  91. * @extends {Component}
  92. */
  93. class RemoteVideoMenuTriggerButton extends Component<Props> {
  94. /**
  95. * Implements React's {@link Component#render()}.
  96. *
  97. * @inheritdoc
  98. * @returns {ReactElement}
  99. */
  100. render() {
  101. const content = this._renderRemoteVideoMenu();
  102. if (!content) {
  103. return null;
  104. }
  105. const username = this.props._participantDisplayName;
  106. return (
  107. <Popover
  108. content = { content }
  109. overflowDrawer = { this.props._overflowDrawer }
  110. position = { this.props._menuPosition }>
  111. <span className = 'popover-trigger remote-video-menu-trigger'>
  112. <Icon
  113. ariaLabel = { this.props.t('dialog.remoteUserControls', { username }) }
  114. role = 'button'
  115. size = '1.4em'
  116. src = { IconMenuThumb }
  117. tabIndex = { 0 }
  118. title = { this.props.t('dialog.remoteUserControls', { username }) } />
  119. </span>
  120. </Popover>
  121. );
  122. }
  123. /**
  124. * Creates a new {@code VideoMenu} with buttons for interacting with
  125. * the remote participant.
  126. *
  127. * @private
  128. * @returns {ReactElement}
  129. */
  130. _renderRemoteVideoMenu() {
  131. const {
  132. _disableKick,
  133. _disableRemoteMute,
  134. _disableGrantModerator,
  135. _isModerator,
  136. dispatch,
  137. initialVolumeValue,
  138. onVolumeChange,
  139. _remoteControlState,
  140. participantID
  141. } = this.props;
  142. const buttons = [];
  143. if (_isModerator) {
  144. if (!_disableRemoteMute) {
  145. buttons.push(
  146. <MuteButton
  147. key = 'mute'
  148. participantID = { participantID } />
  149. );
  150. buttons.push(
  151. <MuteEveryoneElseButton
  152. key = 'mute-others'
  153. participantID = { participantID } />
  154. );
  155. buttons.push(
  156. <MuteVideoButton
  157. key = 'mute-video'
  158. participantID = { participantID } />
  159. );
  160. buttons.push(
  161. <MuteEveryoneElsesVideoButton
  162. key = 'mute-others-video'
  163. participantID = { participantID } />
  164. );
  165. }
  166. if (!_disableGrantModerator) {
  167. buttons.push(
  168. <GrantModeratorButton
  169. key = 'grant-moderator'
  170. participantID = { participantID } />
  171. );
  172. }
  173. if (!_disableKick) {
  174. buttons.push(
  175. <KickButton
  176. key = 'kick'
  177. participantID = { participantID } />
  178. );
  179. }
  180. }
  181. if (_remoteControlState) {
  182. let onRemoteControlToggle = null;
  183. if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  184. onRemoteControlToggle = () => dispatch(stopController(true));
  185. } else if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  186. onRemoteControlToggle = () => dispatch(requestRemoteControl(participantID));
  187. }
  188. buttons.push(
  189. <RemoteControlButton
  190. key = 'remote-control'
  191. onClick = { onRemoteControlToggle }
  192. participantID = { participantID }
  193. remoteControlState = { _remoteControlState } />
  194. );
  195. }
  196. buttons.push(
  197. <PrivateMessageMenuButton
  198. key = 'privateMessage'
  199. participantID = { participantID } />
  200. );
  201. if (onVolumeChange && typeof initialVolumeValue === 'number' && !isNaN(initialVolumeValue)) {
  202. buttons.push(
  203. <VolumeSlider
  204. initialValue = { initialVolumeValue }
  205. key = 'volume-slider'
  206. onChange = { onVolumeChange } />
  207. );
  208. }
  209. if (buttons.length > 0) {
  210. return (
  211. <VideoMenu id = { participantID }>
  212. { buttons }
  213. </VideoMenu>
  214. );
  215. }
  216. return null;
  217. }
  218. }
  219. /**
  220. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  221. *
  222. * @param {Object} state - The Redux state.
  223. * @param {Object} ownProps - The own props of the component.
  224. * @private
  225. * @returns {Props}
  226. */
  227. function _mapStateToProps(state, ownProps) {
  228. const { participantID } = ownProps;
  229. const localParticipant = getLocalParticipant(state);
  230. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  231. const { disableKick, disableGrantModerator } = remoteVideoMenu;
  232. let _remoteControlState = null;
  233. const participant = getParticipantById(state, participantID);
  234. const _participantDisplayName = participant.name;
  235. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  236. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  237. const { active, controller } = state['features/remote-control'];
  238. const { requestedParticipant, controlled } = controller;
  239. const activeParticipant = requestedParticipant || controlled;
  240. const { overflowDrawer } = state['features/toolbox'];
  241. if (_supportsRemoteControl
  242. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  243. if (requestedParticipant === participantID) {
  244. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  245. } else if (controlled) {
  246. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  247. } else {
  248. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  249. }
  250. }
  251. const currentLayout = getCurrentLayout(state);
  252. let _menuPosition;
  253. switch (currentLayout) {
  254. case LAYOUTS.TILE_VIEW:
  255. _menuPosition = 'left-start';
  256. break;
  257. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  258. _menuPosition = 'left-end';
  259. break;
  260. default:
  261. _menuPosition = 'auto';
  262. }
  263. return {
  264. _isModerator: Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR),
  265. _disableKick: Boolean(disableKick),
  266. _disableRemoteMute: Boolean(disableRemoteMute),
  267. _remoteControlState,
  268. _menuPosition,
  269. _overflowDrawer: overflowDrawer,
  270. _participantDisplayName,
  271. _disableGrantModerator: Boolean(disableGrantModerator)
  272. };
  273. }
  274. export default translate(connect(_mapStateToProps)(RemoteVideoMenuTriggerButton));