Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

LocalVideoMenuTriggerButton.js 9.4KB

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