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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 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 VideoMenu}.
  77. *
  78. * @extends {Component}
  79. */
  80. class RemoteVideoMenuTriggerButton extends Component<Props> {
  81. /**
  82. * Implements React's {@link Component#render()}.
  83. *
  84. * @inheritdoc
  85. * @returns {ReactElement}
  86. */
  87. render() {
  88. const content = this._renderRemoteVideoMenu();
  89. if (!content) {
  90. return null;
  91. }
  92. return (
  93. <Popover
  94. content = { content }
  95. overflowDrawer = { this.props._overflowDrawer }
  96. position = { this.props._menuPosition }>
  97. <span
  98. className = 'popover-trigger remote-video-menu-trigger'>
  99. <Icon
  100. size = '1em'
  101. src = { IconMenuThumb }
  102. title = 'Remote user controls' />
  103. </span>
  104. </Popover>
  105. );
  106. }
  107. /**
  108. * Creates a new {@code VideoMenu} with buttons for interacting with
  109. * the remote participant.
  110. *
  111. * @private
  112. * @returns {ReactElement}
  113. */
  114. _renderRemoteVideoMenu() {
  115. const {
  116. _disableKick,
  117. _disableRemoteMute,
  118. _isModerator,
  119. dispatch,
  120. initialVolumeValue,
  121. onVolumeChange,
  122. _remoteControlState,
  123. participantID
  124. } = this.props;
  125. const buttons = [];
  126. if (_isModerator) {
  127. if (!_disableRemoteMute) {
  128. buttons.push(
  129. <MuteButton
  130. key = 'mute'
  131. participantID = { participantID } />
  132. );
  133. buttons.push(
  134. <MuteEveryoneElseButton
  135. key = 'mute-others'
  136. participantID = { participantID } />
  137. );
  138. buttons.push(
  139. <MuteVideoButton
  140. key = 'mute-video'
  141. participantID = { participantID } />
  142. );
  143. buttons.push(
  144. <MuteEveryoneElsesVideoButton
  145. key = 'mute-others-video'
  146. participantID = { participantID } />
  147. );
  148. }
  149. buttons.push(
  150. <GrantModeratorButton
  151. key = 'grant-moderator'
  152. participantID = { participantID } />
  153. );
  154. if (!_disableKick) {
  155. buttons.push(
  156. <KickButton
  157. key = 'kick'
  158. participantID = { participantID } />
  159. );
  160. }
  161. }
  162. if (_remoteControlState) {
  163. let onRemoteControlToggle = null;
  164. if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  165. onRemoteControlToggle = () => dispatch(stopController(true));
  166. } else if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  167. onRemoteControlToggle = () => dispatch(requestRemoteControl(participantID));
  168. }
  169. buttons.push(
  170. <RemoteControlButton
  171. key = 'remote-control'
  172. onClick = { onRemoteControlToggle }
  173. participantID = { participantID }
  174. remoteControlState = { _remoteControlState } />
  175. );
  176. }
  177. buttons.push(
  178. <PrivateMessageMenuButton
  179. key = 'privateMessage'
  180. participantID = { participantID } />
  181. );
  182. if (onVolumeChange && typeof initialVolumeValue === 'number' && !isNaN(initialVolumeValue)) {
  183. buttons.push(
  184. <VolumeSlider
  185. initialValue = { initialVolumeValue }
  186. key = 'volume-slider'
  187. onChange = { onVolumeChange } />
  188. );
  189. }
  190. if (buttons.length > 0) {
  191. return (
  192. <VideoMenu id = { participantID }>
  193. { buttons }
  194. </VideoMenu>
  195. );
  196. }
  197. return null;
  198. }
  199. }
  200. /**
  201. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  202. *
  203. * @param {Object} state - The Redux state.
  204. * @param {Object} ownProps - The own props of the component.
  205. * @private
  206. * @returns {Props}
  207. */
  208. function _mapStateToProps(state, ownProps) {
  209. const { participantID } = ownProps;
  210. const localParticipant = getLocalParticipant(state);
  211. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  212. const { disableKick } = remoteVideoMenu;
  213. let _remoteControlState = null;
  214. const participant = getParticipantById(state, participantID);
  215. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  216. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  217. const { active, controller } = state['features/remote-control'];
  218. const { requestedParticipant, controlled } = controller;
  219. const activeParticipant = requestedParticipant || controlled;
  220. const { overflowDrawer } = state['features/toolbox'];
  221. if (_supportsRemoteControl
  222. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  223. if (requestedParticipant === participantID) {
  224. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  225. } else if (controlled) {
  226. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  227. } else {
  228. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  229. }
  230. }
  231. const currentLayout = getCurrentLayout(state);
  232. let _menuPosition;
  233. switch (currentLayout) {
  234. case LAYOUTS.TILE_VIEW:
  235. _menuPosition = 'left-start';
  236. break;
  237. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  238. _menuPosition = 'left-end';
  239. break;
  240. default:
  241. _menuPosition = 'auto';
  242. }
  243. return {
  244. _isModerator: Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR),
  245. _disableKick: Boolean(disableKick),
  246. _disableRemoteMute: Boolean(disableRemoteMute),
  247. _remoteControlState,
  248. _menuPosition,
  249. _overflowDrawer: overflowDrawer
  250. };
  251. }
  252. export default connect(_mapStateToProps)(RemoteVideoMenuTriggerButton);