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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. * 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 the popover has been displayed.
  66. */
  67. onMenuDisplay: Function,
  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. * Initializes a new {#@code RemoteVideoMenuTriggerButton} instance.
  96. *
  97. * @param {Object} props - The read-only properties with which the new
  98. * instance is to be initialized.
  99. */
  100. constructor(props: Object) {
  101. super(props);
  102. // Bind event handler so it is only bound once for every instance.
  103. this._onShowRemoteMenu = this._onShowRemoteMenu.bind(this);
  104. }
  105. /**
  106. * Implements React's {@link Component#render()}.
  107. *
  108. * @inheritdoc
  109. * @returns {ReactElement}
  110. */
  111. render() {
  112. const content = this._renderRemoteVideoMenu();
  113. if (!content) {
  114. return null;
  115. }
  116. return (
  117. <Popover
  118. content = { content }
  119. onPopoverOpen = { this._onShowRemoteMenu }
  120. position = { this.props._menuPosition }>
  121. <span
  122. className = 'popover-trigger remote-video-menu-trigger'>
  123. <Icon
  124. size = '1em'
  125. src = { IconMenuThumb }
  126. title = 'Remote user controls' />
  127. </span>
  128. </Popover>
  129. );
  130. }
  131. _onShowRemoteMenu: () => void;
  132. /**
  133. * Opens the {@code RemoteVideoMenu}.
  134. *
  135. * @private
  136. * @returns {void}
  137. */
  138. _onShowRemoteMenu() {
  139. this.props.onMenuDisplay();
  140. }
  141. /**
  142. * Creates a new {@code RemoteVideoMenu} with buttons for interacting with
  143. * the remote participant.
  144. *
  145. * @private
  146. * @returns {ReactElement}
  147. */
  148. _renderRemoteVideoMenu() {
  149. const {
  150. _disableKick,
  151. _disableRemoteMute,
  152. _isAudioMuted,
  153. _isModerator,
  154. dispatch,
  155. initialVolumeValue,
  156. onVolumeChange,
  157. _remoteControlState,
  158. participantID
  159. } = this.props;
  160. const buttons = [];
  161. if (_isModerator) {
  162. if (!_disableRemoteMute) {
  163. buttons.push(
  164. <MuteButton
  165. isAudioMuted = { _isAudioMuted }
  166. key = 'mute'
  167. participantID = { participantID } />
  168. );
  169. buttons.push(
  170. <MuteEveryoneElseButton
  171. key = 'mute-others'
  172. participantID = { participantID } />
  173. );
  174. }
  175. buttons.push(
  176. <GrantModeratorButton
  177. key = 'grant-moderator'
  178. participantID = { participantID } />
  179. );
  180. if (!_disableKick) {
  181. buttons.push(
  182. <KickButton
  183. key = 'kick'
  184. participantID = { participantID } />
  185. );
  186. }
  187. }
  188. if (_remoteControlState) {
  189. let onRemoteControlToggle = null;
  190. if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.STARTED) {
  191. onRemoteControlToggle = () => dispatch(stopController(true));
  192. } else if (_remoteControlState === REMOTE_CONTROL_MENU_STATES.NOT_STARTED) {
  193. onRemoteControlToggle = () => dispatch(requestRemoteControl(participantID));
  194. }
  195. buttons.push(
  196. <RemoteControlButton
  197. key = 'remote-control'
  198. onClick = { onRemoteControlToggle }
  199. participantID = { participantID }
  200. remoteControlState = { _remoteControlState } />
  201. );
  202. }
  203. buttons.push(
  204. <PrivateMessageMenuButton
  205. key = 'privateMessage'
  206. participantID = { participantID } />
  207. );
  208. if (onVolumeChange) {
  209. buttons.push(
  210. <VolumeSlider
  211. initialValue = { initialVolumeValue }
  212. key = 'volume-slider'
  213. onChange = { onVolumeChange } />
  214. );
  215. }
  216. if (buttons.length > 0) {
  217. return (
  218. <RemoteVideoMenu id = { participantID }>
  219. { buttons }
  220. </RemoteVideoMenu>
  221. );
  222. }
  223. return null;
  224. }
  225. }
  226. /**
  227. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  228. *
  229. * @param {Object} state - The Redux state.
  230. * @param {Object} ownProps - The own props of the component.
  231. * @private
  232. * @returns {{
  233. * _isAudioMuted: boolean,
  234. * _isModerator: boolean,
  235. * _disableKick: boolean,
  236. * _disableRemoteMute: boolean,
  237. * _menuPosition: string,
  238. * _remoteControlState: number
  239. * }}
  240. */
  241. function _mapStateToProps(state, ownProps) {
  242. const { participantID } = ownProps;
  243. const tracks = state['features/base/tracks'];
  244. const localParticipant = getLocalParticipant(state);
  245. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  246. const { disableKick } = remoteVideoMenu;
  247. let _remoteControlState = null;
  248. const participant = getParticipantById(state, participantID);
  249. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  250. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  251. const { active, controller } = state['features/remote-control'];
  252. const { requestedParticipant, controlled } = controller;
  253. const activeParticipant = requestedParticipant || controlled;
  254. if (_supportsRemoteControl
  255. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  256. if (requestedParticipant === participantID) {
  257. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  258. } else if (controlled) {
  259. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  260. } else {
  261. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  262. }
  263. }
  264. const currentLayout = getCurrentLayout(state);
  265. let _menuPosition;
  266. switch (currentLayout) {
  267. case LAYOUTS.TILE_VIEW:
  268. _menuPosition = 'left top';
  269. break;
  270. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  271. _menuPosition = 'left bottom';
  272. break;
  273. default:
  274. _menuPosition = 'top center';
  275. }
  276. return {
  277. _isAudioMuted: isRemoteTrackMuted(tracks, MEDIA_TYPE.AUDIO, participantID) || false,
  278. _isModerator: Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR),
  279. _disableKick: Boolean(disableKick),
  280. _disableRemoteMute: Boolean(disableRemoteMute),
  281. _remoteControlState,
  282. _menuPosition
  283. };
  284. }
  285. export default connect(_mapStateToProps)(RemoteVideoMenuTriggerButton);