您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RemoteVideoMenuTriggerButton.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 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 RemoteVideoMenu}.
  77. *
  78. * @extends {Component}
  79. */
  80. class RemoteVideoMenuTriggerButton extends Component<Props> {
  81. /**
  82. * The internal reference to topmost DOM/HTML element backing the React
  83. * {@code Component}. Accessed directly for associating an element as
  84. * the trigger for a popover.
  85. *
  86. * @private
  87. * @type {HTMLDivElement}
  88. */
  89. _rootElement = null;
  90. /**
  91. * Implements React's {@link Component#render()}.
  92. *
  93. * @inheritdoc
  94. * @returns {ReactElement}
  95. */
  96. render() {
  97. const content = this._renderRemoteVideoMenu();
  98. if (!content) {
  99. return null;
  100. }
  101. return (
  102. <Popover
  103. content = { content }
  104. position = { this.props._menuPosition }>
  105. <span
  106. className = 'popover-trigger remote-video-menu-trigger'>
  107. <Icon
  108. size = '1em'
  109. src = { IconMenuThumb }
  110. title = 'Remote user controls' />
  111. </span>
  112. </Popover>
  113. );
  114. }
  115. /**
  116. * Creates a new {@code RemoteVideoMenu} with buttons for interacting with
  117. * the remote participant.
  118. *
  119. * @private
  120. * @returns {ReactElement}
  121. */
  122. _renderRemoteVideoMenu() {
  123. const {
  124. _disableKick,
  125. _disableRemoteMute,
  126. _isAudioMuted,
  127. _isModerator,
  128. dispatch,
  129. initialVolumeValue,
  130. onVolumeChange,
  131. _remoteControlState,
  132. participantID
  133. } = this.props;
  134. const buttons = [];
  135. if (_isModerator) {
  136. if (!_disableRemoteMute) {
  137. buttons.push(
  138. <MuteButton
  139. isAudioMuted = { _isAudioMuted }
  140. key = 'mute'
  141. participantID = { participantID } />
  142. );
  143. buttons.push(
  144. <MuteEveryoneElseButton
  145. key = 'mute-others'
  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 && initialVolumeValue && !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. <RemoteVideoMenu id = { participantID }>
  193. { buttons }
  194. </RemoteVideoMenu>
  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 {{
  207. * _isAudioMuted: boolean,
  208. * _isModerator: boolean,
  209. * _disableKick: boolean,
  210. * _disableRemoteMute: boolean,
  211. * _menuPosition: string,
  212. * _remoteControlState: number
  213. * }}
  214. */
  215. function _mapStateToProps(state, ownProps) {
  216. const { participantID } = ownProps;
  217. const tracks = state['features/base/tracks'];
  218. const localParticipant = getLocalParticipant(state);
  219. const { remoteVideoMenu = {}, disableRemoteMute } = state['features/base/config'];
  220. const { disableKick } = remoteVideoMenu;
  221. let _remoteControlState = null;
  222. const participant = getParticipantById(state, participantID);
  223. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  224. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  225. const { active, controller } = state['features/remote-control'];
  226. const { requestedParticipant, controlled } = controller;
  227. const activeParticipant = requestedParticipant || controlled;
  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 top';
  243. break;
  244. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  245. _menuPosition = 'left bottom';
  246. break;
  247. default:
  248. _menuPosition = 'top center';
  249. }
  250. return {
  251. _isAudioMuted: isRemoteTrackMuted(tracks, MEDIA_TYPE.AUDIO, participantID) || false,
  252. _isModerator: Boolean(localParticipant?.role === PARTICIPANT_ROLE.MODERATOR),
  253. _disableKick: Boolean(disableKick),
  254. _disableRemoteMute: Boolean(disableRemoteMute),
  255. _remoteControlState,
  256. _menuPosition
  257. };
  258. }
  259. export default connect(_mapStateToProps)(RemoteVideoMenuTriggerButton);