Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

RemoteVideoMenuTriggerButton.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // @flow
  2. /* eslint-disable react/jsx-handler-names */
  3. import { withStyles } from '@material-ui/styles';
  4. import React, { Component } from 'react';
  5. import { batch } from 'react-redux';
  6. import ConnectionIndicatorContent from
  7. '../../../../features/connection-indicator/components/web/ConnectionIndicatorContent';
  8. import { isMobileBrowser } from '../../../base/environment/utils';
  9. import { translate } from '../../../base/i18n';
  10. import { Icon, IconHorizontalPoints } from '../../../base/icons';
  11. import { getParticipantById } from '../../../base/participants';
  12. import { Popover } from '../../../base/popover';
  13. import { connect } from '../../../base/redux';
  14. import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions';
  15. import { THUMBNAIL_TYPE } from '../../../filmstrip';
  16. import { renderConnectionStatus } from '../../actions.web';
  17. import ParticipantContextMenu from './ParticipantContextMenu';
  18. import { REMOTE_CONTROL_MENU_STATES } from './RemoteControlButton';
  19. declare var $: Object;
  20. /**
  21. * The type of the React {@code Component} props of
  22. * {@link RemoteVideoMenuTriggerButton}.
  23. */
  24. type Props = {
  25. /**
  26. * Hides popover.
  27. */
  28. hidePopover: Function,
  29. /**
  30. * Whether the popover is visible or not.
  31. */
  32. popoverVisible: boolean,
  33. /**
  34. * Shows popover.
  35. */
  36. showPopover: Function,
  37. /**
  38. * The position relative to the trigger the remote menu should display
  39. * from. Valid values are those supported by AtlasKit
  40. * {@code InlineDialog}.
  41. */
  42. _menuPosition: string,
  43. /**
  44. * Whether to display the Popover as a drawer.
  45. */
  46. _overflowDrawer: boolean,
  47. /**
  48. * Participant reference.
  49. */
  50. _participant: Object,
  51. /**
  52. * The current state of the participant's remote control session.
  53. */
  54. _remoteControlState: number,
  55. /**
  56. * Whether or not the button should be visible.
  57. */
  58. buttonVisible: boolean,
  59. /**
  60. * An object containing the CSS classes.
  61. */
  62. classes: Object,
  63. /**
  64. * The redux dispatch function.
  65. */
  66. dispatch: Function,
  67. /**
  68. * The ID for the participant on which the remote video menu will act.
  69. */
  70. participantID: string,
  71. /**
  72. * Whether the remote video context menu is disabled.
  73. */
  74. _disabled: Boolean,
  75. /**
  76. * The ID for the participant on which the remote video menu will act.
  77. */
  78. _participantDisplayName: string,
  79. /**
  80. * Whether the popover should render the Connection Info stats.
  81. */
  82. _showConnectionInfo: Boolean,
  83. /**
  84. * Invoked to obtain translated strings.
  85. */
  86. t: Function
  87. };
  88. const styles = theme => {
  89. return {
  90. triggerButton: {
  91. backgroundColor: theme.palette.action01,
  92. padding: '3px',
  93. display: 'inline-block',
  94. borderRadius: '4px'
  95. },
  96. contextMenu: {
  97. position: 'relative',
  98. marginTop: 0,
  99. right: 'auto',
  100. padding: '0',
  101. marginRight: '4px',
  102. marginBottom: '4px'
  103. }
  104. };
  105. };
  106. /**
  107. * React {@code Component} for displaying an icon associated with opening the
  108. * the {@code VideoMenu}.
  109. *
  110. * @augments {Component}
  111. */
  112. class RemoteVideoMenuTriggerButton extends Component<Props> {
  113. /**
  114. * Initializes a new RemoteVideoMenuTriggerButton instance.
  115. *
  116. * @param {Object} props - The read-only React Component props with which
  117. * the new instance is to be initialized.
  118. */
  119. constructor(props: Props) {
  120. super(props);
  121. this._onPopoverClose = this._onPopoverClose.bind(this);
  122. this._onPopoverOpen = this._onPopoverOpen.bind(this);
  123. }
  124. /**
  125. * Implements React's {@link Component#render()}.
  126. *
  127. * @inheritdoc
  128. * @returns {ReactElement}
  129. */
  130. render() {
  131. const {
  132. _disabled,
  133. _overflowDrawer,
  134. _showConnectionInfo,
  135. _participantDisplayName,
  136. buttonVisible,
  137. classes,
  138. participantID,
  139. popoverVisible
  140. } = this.props;
  141. let content;
  142. if (_showConnectionInfo) {
  143. content = <ConnectionIndicatorContent participantId = { participantID } />;
  144. } else if (!_disabled) {
  145. content = this._renderRemoteVideoMenu();
  146. }
  147. if (!content) {
  148. return null;
  149. }
  150. const username = _participantDisplayName;
  151. return (
  152. <Popover
  153. content = { content }
  154. id = 'remote-video-menu-trigger'
  155. onPopoverClose = { this._onPopoverClose }
  156. onPopoverOpen = { this._onPopoverOpen }
  157. position = { this.props._menuPosition }
  158. visible = { popoverVisible }>
  159. {!_overflowDrawer && buttonVisible && !_disabled && (
  160. <span
  161. className = { classes.triggerButton }
  162. role = 'button'>
  163. {!isMobileBrowser() && <Icon
  164. ariaLabel = { this.props.t('dialog.remoteUserControls', { username }) }
  165. size = { 18 }
  166. src = { IconHorizontalPoints }
  167. tabIndex = { 0 }
  168. title = { this.props.t('dialog.remoteUserControls', { username }) } />
  169. }
  170. </span>
  171. )}
  172. </Popover>
  173. );
  174. }
  175. _onPopoverOpen: () => void;
  176. /**
  177. * Disable and hide toolbox while context menu is open.
  178. *
  179. * @returns {void}
  180. */
  181. _onPopoverOpen() {
  182. const { dispatch, showPopover } = this.props;
  183. showPopover();
  184. dispatch(setParticipantContextMenuOpen(true));
  185. }
  186. _onPopoverClose: () => void;
  187. /**
  188. * Render normal context menu next time popover dialog opens.
  189. *
  190. * @returns {void}
  191. */
  192. _onPopoverClose() {
  193. const { dispatch, hidePopover } = this.props;
  194. hidePopover();
  195. batch(() => {
  196. dispatch(setParticipantContextMenuOpen(false));
  197. dispatch(renderConnectionStatus(false));
  198. });
  199. }
  200. /**
  201. * Creates a new {@code VideoMenu} with buttons for interacting with
  202. * the remote participant.
  203. *
  204. * @private
  205. * @returns {ReactElement}
  206. */
  207. _renderRemoteVideoMenu() {
  208. const { _participant, _remoteControlState, classes } = this.props;
  209. return (
  210. <ParticipantContextMenu
  211. className = { classes.contextMenu }
  212. onSelect = { this._onPopoverClose }
  213. participant = { _participant }
  214. remoteControlState = { _remoteControlState }
  215. thumbnailMenu = { true } />
  216. );
  217. }
  218. }
  219. /**
  220. * Maps (parts of) the Redux state to the associated {@code RemoteVideoMenuTriggerButton}'s props.
  221. *
  222. * @param {Object} state - The Redux state.
  223. * @param {Object} ownProps - The own props of the component.
  224. * @private
  225. * @returns {Props}
  226. */
  227. function _mapStateToProps(state, ownProps) {
  228. const { participantID, thumbnailType } = ownProps;
  229. let _remoteControlState = null;
  230. const participant = getParticipantById(state, participantID);
  231. const _participantDisplayName = participant?.name;
  232. const _isRemoteControlSessionActive = participant?.remoteControlSessionStatus ?? false;
  233. const _supportsRemoteControl = participant?.supportsRemoteControl ?? false;
  234. const { active, controller } = state['features/remote-control'];
  235. const { requestedParticipant, controlled } = controller;
  236. const activeParticipant = requestedParticipant || controlled;
  237. const { overflowDrawer } = state['features/toolbox'];
  238. const { showConnectionInfo } = state['features/base/connection'];
  239. const { remoteVideoMenu } = state['features/base/config'];
  240. if (_supportsRemoteControl
  241. && ((!active && !_isRemoteControlSessionActive) || activeParticipant === participantID)) {
  242. if (requestedParticipant === participantID) {
  243. _remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  244. } else if (controlled) {
  245. _remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  246. } else {
  247. _remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  248. }
  249. }
  250. let _menuPosition;
  251. switch (thumbnailType) {
  252. case THUMBNAIL_TYPE.TILE:
  253. _menuPosition = 'left-start';
  254. break;
  255. case THUMBNAIL_TYPE.VERTICAL:
  256. _menuPosition = 'left-end';
  257. break;
  258. case THUMBNAIL_TYPE.HORIZONTAL:
  259. _menuPosition = 'top';
  260. break;
  261. default:
  262. _menuPosition = 'auto';
  263. }
  264. return {
  265. _disabled: remoteVideoMenu?.disabled,
  266. _menuPosition,
  267. _overflowDrawer: overflowDrawer,
  268. _participant: participant,
  269. _participantDisplayName,
  270. _remoteControlState,
  271. _showConnectionInfo: showConnectionInfo
  272. };
  273. }
  274. export default translate(connect(_mapStateToProps)(
  275. withStyles(styles)(RemoteVideoMenuTriggerButton)));