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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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, 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 MuteEveryoneElseButton from './MuteEveryoneElseButton';
  10. import {
  11. GrantModeratorButton,
  12. MuteButton,
  13. KickButton,
  14. PrivateMessageMenuButton,
  15. RemoteControlButton,
  16. RemoteVideoMenu,
  17. VolumeSlider
  18. } from './';
  19. declare var $: Object;
  20. declare var interfaceConfig: Object;
  21. /**
  22. * The type of the React {@code Component} props of
  23. * {@link RemoteVideoMenuTriggerButton}.
  24. */
  25. type Props = {
  26. /**
  27. * Whether or not to display the kick button.
  28. */
  29. _disableKick: boolean,
  30. /**
  31. * Whether or not to display the remote mute buttons.
  32. */
  33. _disableRemoteMute: Boolean,
  34. /**
  35. * Whether or not the participant is currently muted.
  36. */
  37. _isAudioMuted: boolean,
  38. /**
  39. * Whether or not the participant is a conference moderator.
  40. */
  41. _isModerator: boolean,
  42. /**
  43. * A value between 0 and 1 indicating the volume of the participant's
  44. * audio element.
  45. */
  46. initialVolumeValue: number,
  47. /**
  48. * Callback to invoke when the popover has been displayed.
  49. */
  50. onMenuDisplay: Function,
  51. /**
  52. * Callback to invoke choosing to start a remote control session with
  53. * the participant.
  54. */
  55. onRemoteControlToggle: Function,
  56. /**
  57. * Callback to invoke when changing the level of the participant's
  58. * audio element.
  59. */
  60. onVolumeChange: Function,
  61. /**
  62. * The position relative to the trigger the remote menu should display
  63. * from. Valid values are those supported by AtlasKit
  64. * {@code InlineDialog}.
  65. */
  66. menuPosition: string,
  67. /**
  68. * The ID for the participant on which the remote video menu will act.
  69. */
  70. participantID: string,
  71. /**
  72. * The current state of the participant's remote control session.
  73. */
  74. remoteControlState: number
  75. };
  76. /**
  77. * React {@code Component} for displaying an icon associated with opening the
  78. * the {@code RemoteVideoMenu}.
  79. *
  80. * @extends {Component}
  81. */
  82. class RemoteVideoMenuTriggerButton extends Component<Props> {
  83. /**
  84. * The internal reference to topmost DOM/HTML element backing the React
  85. * {@code Component}. Accessed directly for associating an element as
  86. * the trigger for a popover.
  87. *
  88. * @private
  89. * @type {HTMLDivElement}
  90. */
  91. _rootElement = null;
  92. /**
  93. * Initializes a new {#@code RemoteVideoMenuTriggerButton} instance.
  94. *
  95. * @param {Object} props - The read-only properties with which the new
  96. * instance is to be initialized.
  97. */
  98. constructor(props: Object) {
  99. super(props);
  100. // Bind event handler so it is only bound once for every instance.
  101. this._onShowRemoteMenu = this._onShowRemoteMenu.bind(this);
  102. }
  103. /**
  104. * Implements React's {@link Component#render()}.
  105. *
  106. * @inheritdoc
  107. * @returns {ReactElement}
  108. */
  109. render() {
  110. const content = this._renderRemoteVideoMenu();
  111. if (!content) {
  112. return null;
  113. }
  114. return (
  115. <Popover
  116. content = { content }
  117. onPopoverOpen = { this._onShowRemoteMenu }
  118. position = { this.props.menuPosition }>
  119. <span
  120. className = 'popover-trigger remote-video-menu-trigger'>
  121. <Icon
  122. size = '1em'
  123. src = { IconMenuThumb }
  124. title = 'Remote user controls' />
  125. </span>
  126. </Popover>
  127. );
  128. }
  129. _onShowRemoteMenu: () => void;
  130. /**
  131. * Opens the {@code RemoteVideoMenu}.
  132. *
  133. * @private
  134. * @returns {void}
  135. */
  136. _onShowRemoteMenu() {
  137. this.props.onMenuDisplay();
  138. }
  139. /**
  140. * Creates a new {@code RemoteVideoMenu} with buttons for interacting with
  141. * the remote participant.
  142. *
  143. * @private
  144. * @returns {ReactElement}
  145. */
  146. _renderRemoteVideoMenu() {
  147. const {
  148. _disableKick,
  149. _disableRemoteMute,
  150. _isAudioMuted,
  151. _isModerator,
  152. initialVolumeValue,
  153. onRemoteControlToggle,
  154. onVolumeChange,
  155. remoteControlState,
  156. participantID
  157. } = this.props;
  158. const buttons = [];
  159. if (_isModerator) {
  160. if (!_disableRemoteMute) {
  161. buttons.push(
  162. <MuteButton
  163. isAudioMuted = { _isAudioMuted }
  164. key = 'mute'
  165. participantID = { participantID } />
  166. );
  167. buttons.push(
  168. <MuteEveryoneElseButton
  169. key = 'mute-others'
  170. participantID = { participantID } />
  171. );
  172. }
  173. buttons.push(
  174. <GrantModeratorButton
  175. key = 'grant-moderator'
  176. participantID = { participantID } />
  177. );
  178. if (!_disableKick) {
  179. buttons.push(
  180. <KickButton
  181. key = 'kick'
  182. participantID = { participantID } />
  183. );
  184. }
  185. }
  186. if (remoteControlState) {
  187. buttons.push(
  188. <RemoteControlButton
  189. key = 'remote-control'
  190. onClick = { onRemoteControlToggle }
  191. participantID = { participantID }
  192. remoteControlState = { remoteControlState } />
  193. );
  194. }
  195. buttons.push(
  196. <PrivateMessageMenuButton
  197. key = 'privateMessage'
  198. participantID = { participantID } />
  199. );
  200. if (onVolumeChange) {
  201. buttons.push(
  202. <VolumeSlider
  203. initialValue = { initialVolumeValue }
  204. key = 'volume-slider'
  205. onChange = { onVolumeChange } />
  206. );
  207. }
  208. if (buttons.length > 0) {
  209. return (
  210. <RemoteVideoMenu id = { participantID }>
  211. { buttons }
  212. </RemoteVideoMenu>
  213. );
  214. }
  215. return null;
  216. }
  217. }
  218. /**
  219. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  220. *
  221. * @param {Object} state - The Redux state.
  222. * @param {Object} ownProps - The own props of the component.
  223. * @private
  224. * @returns {{
  225. * _isModerator: boolean
  226. * }}
  227. */
  228. function _mapStateToProps(state, ownProps) {
  229. const { participantID } = ownProps;
  230. const tracks = state['features/base/tracks'];
  231. const localParticipant = getLocalParticipant(state);
  232. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  233. const { disableKick } = remoteVideoMenu;
  234. return {
  235. _isAudioMuted: isRemoteTrackMuted(tracks, MEDIA_TYPE.AUDIO, participantID) || false,
  236. _isModerator: Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR),
  237. _disableKick: Boolean(disableKick),
  238. _disableRemoteMute: Boolean(disableRemoteMute)
  239. };
  240. }
  241. export default connect(_mapStateToProps)(RemoteVideoMenuTriggerButton);