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

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