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

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