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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { Icon, IconMenuThumb } from '../../../base/icons';
  4. import { MEDIA_TYPE } from '../../../base/media';
  5. import { getLocalParticipant, getParticipantById, PARTICIPANT_ROLE } from '../../../base/participants';
  6. import { Popover } from '../../../base/popover';
  7. import { connect } from '../../../base/redux';
  8. import { isRemoteTrackMuted } from '../../../base/tracks';
  9. import { requestRemoteControl, stopController } from '../../../remote-control';
  10. import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
  11. import MuteEveryoneElseButton from './MuteEveryoneElseButton';
  12. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  13. import {
  14. GrantModeratorButton,
  15. MuteButton,
  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 currently muted.
  39. */
  40. _isAudioMuted: 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 RemoteVideoMenu}.
  81. *
  82. * @extends {Component}
  83. */
  84. class RemoteVideoMenuTriggerButton extends Component<Props> {
  85. /**
  86. * The internal reference to topmost DOM/HTML element backing the React
  87. * {@code Component}. Accessed directly for associating an element as
  88. * the trigger for a popover.
  89. *
  90. * @private
  91. * @type {HTMLDivElement}
  92. */
  93. _rootElement = null;
  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. return (
  106. <Popover
  107. content = { content }
  108. overflowDrawer = { this.props._overflowDrawer }
  109. position = { this.props._menuPosition }>
  110. <span
  111. className = 'popover-trigger remote-video-menu-trigger'>
  112. <Icon
  113. size = '1em'
  114. src = { IconMenuThumb }
  115. title = 'Remote user controls' />
  116. </span>
  117. </Popover>
  118. );
  119. }
  120. /**
  121. * Creates a new {@code RemoteVideoMenu} with buttons for interacting with
  122. * the remote participant.
  123. *
  124. * @private
  125. * @returns {ReactElement}
  126. */
  127. _renderRemoteVideoMenu() {
  128. const {
  129. _disableKick,
  130. _disableRemoteMute,
  131. _isAudioMuted,
  132. _isModerator,
  133. dispatch,
  134. initialVolumeValue,
  135. onVolumeChange,
  136. _remoteControlState,
  137. participantID
  138. } = this.props;
  139. const buttons = [];
  140. if (_isModerator) {
  141. if (!_disableRemoteMute) {
  142. buttons.push(
  143. <MuteButton
  144. isAudioMuted = { _isAudioMuted }
  145. key = 'mute'
  146. participantID = { participantID } />
  147. );
  148. buttons.push(
  149. <MuteEveryoneElseButton
  150. key = 'mute-others'
  151. participantID = { participantID } />
  152. );
  153. }
  154. buttons.push(
  155. <GrantModeratorButton
  156. key = 'grant-moderator'
  157. participantID = { participantID } />
  158. );
  159. if (!_disableKick) {
  160. buttons.push(
  161. <KickButton
  162. key = 'kick'
  163. participantID = { participantID } />
  164. );
  165. }
  166. }
  167. if (_remoteControlState) {
  168. let onRemoteControlToggle = null;
  169. if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  170. onRemoteControlToggle = () => dispatch(stopController(true));
  171. } else if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  172. onRemoteControlToggle = () => dispatch(requestRemoteControl(participantID));
  173. }
  174. buttons.push(
  175. <RemoteControlButton
  176. key = 'remote-control'
  177. onClick = { onRemoteControlToggle }
  178. participantID = { participantID }
  179. remoteControlState = { _remoteControlState } />
  180. );
  181. }
  182. buttons.push(
  183. <PrivateMessageMenuButton
  184. key = 'privateMessage'
  185. participantID = { participantID } />
  186. );
  187. if (onVolumeChange && initialVolumeValue && !isNaN(initialVolumeValue)) {
  188. buttons.push(
  189. <VolumeSlider
  190. initialValue = { initialVolumeValue }
  191. key = 'volume-slider'
  192. onChange = { onVolumeChange } />
  193. );
  194. }
  195. if (buttons.length > 0) {
  196. return (
  197. <RemoteVideoMenu id = { participantID }>
  198. { buttons }
  199. </RemoteVideoMenu>
  200. );
  201. }
  202. return null;
  203. }
  204. }
  205. /**
  206. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  207. *
  208. * @param {Object} state - The Redux state.
  209. * @param {Object} ownProps - The own props of the component.
  210. * @private
  211. * @returns {Props}
  212. */
  213. function _mapStateToProps(state, ownProps) {
  214. const { participantID } = ownProps;
  215. const tracks = state['features/base/tracks'];
  216. const localParticipant = getLocalParticipant(state);
  217. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  218. const { disableKick } = remoteVideoMenu;
  219. let _remoteControlState = null;
  220. const participant = getParticipantById(state, participantID);
  221. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  222. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  223. const { active, controller } = state['features/remote-control'];
  224. const { requestedParticipant, controlled } = controller;
  225. const activeParticipant = requestedParticipant || controlled;
  226. const { overflowDrawer } = state['features/toolbox'];
  227. if (_supportsRemoteControl
  228. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  229. if (requestedParticipant === participantID) {
  230. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  231. } else if (controlled) {
  232. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  233. } else {
  234. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  235. }
  236. }
  237. const currentLayout = getCurrentLayout(state);
  238. let _menuPosition;
  239. switch (currentLayout) {
  240. case LAYOUTS.TILE_VIEW:
  241. _menuPosition = 'left top';
  242. break;
  243. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  244. _menuPosition = 'left bottom';
  245. break;
  246. default:
  247. _menuPosition = 'top center';
  248. }
  249. return {
  250. _isAudioMuted: isRemoteTrackMuted(tracks, MEDIA_TYPE.AUDIO, participantID) || false,
  251. _isModerator: Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR),
  252. _disableKick: Boolean(disableKick),
  253. _disableRemoteMute: Boolean(disableRemoteMute),
  254. _remoteControlState,
  255. _menuPosition,
  256. _overflowDrawer: overflowDrawer
  257. };
  258. }
  259. export default connect(_mapStateToProps)(RemoteVideoMenuTriggerButton);