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 8.8KB

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