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.

LocalVideoMenuTriggerButton.js 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { batch } from 'react-redux';
  4. import { isMobileBrowser } from '../../../base/environment/utils';
  5. import { translate } from '../../../base/i18n';
  6. import { Icon, IconMenuThumb } from '../../../base/icons';
  7. import {
  8. getLocalParticipant
  9. } from '../../../base/participants';
  10. import { Popover } from '../../../base/popover';
  11. import { connect } from '../../../base/redux';
  12. import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions';
  13. import { getLocalVideoTrack } from '../../../base/tracks';
  14. import ConnectionIndicatorContent from '../../../connection-indicator/components/web/ConnectionIndicatorContent';
  15. import { hideToolboxOnTileView } from '../../../toolbox/actions';
  16. import { getCurrentLayout, LAYOUTS } from '../../../video-layout';
  17. import { renderConnectionStatus } from '../../actions.web';
  18. import ConnectionStatusButton from './ConnectionStatusButton';
  19. import FlipLocalVideoButton from './FlipLocalVideoButton';
  20. import VideoMenu from './VideoMenu';
  21. /**
  22. * The type of the React {@code Component} props of
  23. * {@link LocalVideoMenuTriggerButton}.
  24. */
  25. type Props = {
  26. /**
  27. * The redux dispatch function.
  28. */
  29. dispatch: Function,
  30. /**
  31. * Gets a ref to the current component instance.
  32. */
  33. getRef: Function,
  34. /**
  35. * The id of the local participant.
  36. */
  37. _localParticipantId: string,
  38. /**
  39. * The position relative to the trigger the local video menu should display
  40. * from. Valid values are those supported by AtlasKit
  41. * {@code InlineDialog}.
  42. */
  43. _menuPosition: string,
  44. /**
  45. * Whether to display the Popover as a drawer.
  46. */
  47. _overflowDrawer: boolean,
  48. /**
  49. * Whether to render the connection info pane.
  50. */
  51. _showConnectionInfo: boolean,
  52. /**
  53. * Shows/hides the local video flip button.
  54. */
  55. _showLocalVideoFlipButton: boolean,
  56. /**
  57. * Invoked to obtain translated strings.
  58. */
  59. t: Function
  60. };
  61. /**
  62. * React Component for displaying an icon associated with opening the
  63. * the video menu for the local participant.
  64. *
  65. * @extends {Component}
  66. */
  67. class LocalVideoMenuTriggerButton extends Component<Props> {
  68. /**
  69. * Reference to the Popover instance.
  70. */
  71. popoverRef: Object;
  72. /**
  73. * Initializes a new LocalVideoMenuTriggerButton instance.
  74. *
  75. * @param {Object} props - The read-only React Component props with which
  76. * the new instance is to be initialized.
  77. */
  78. constructor(props: Props) {
  79. super(props);
  80. this.popoverRef = React.createRef();
  81. this._onPopoverClose = this._onPopoverClose.bind(this);
  82. this._onPopoverOpen = this._onPopoverOpen.bind(this);
  83. }
  84. /**
  85. * Triggers showing the popover's context menu.
  86. *
  87. * @returns {void}
  88. */
  89. showContextMenu() {
  90. if (this.popoverRef && this.popoverRef.current) {
  91. this.popoverRef.current.showDialog();
  92. }
  93. }
  94. /**
  95. * Calls the ref(instance) getter.
  96. *
  97. * @inheritdoc
  98. * @returns {void}
  99. */
  100. componentDidMount() {
  101. if (this.props.getRef) {
  102. this.props.getRef(this);
  103. }
  104. }
  105. /**
  106. * Calls the ref(instance) getter.
  107. *
  108. * @inheritdoc
  109. * @returns {void}
  110. */
  111. componentWillUnmount() {
  112. if (this.props.getRef) {
  113. this.props.getRef(null);
  114. }
  115. }
  116. /**
  117. * Implements React's {@link Component#render()}.
  118. *
  119. * @inheritdoc
  120. * @returns {ReactElement}
  121. */
  122. render() {
  123. const {
  124. _localParticipantId,
  125. _menuPosition,
  126. _showConnectionInfo,
  127. _overflowDrawer,
  128. _showLocalVideoFlipButton,
  129. t
  130. } = this.props;
  131. const content = _showConnectionInfo
  132. ? <ConnectionIndicatorContent participantId = { _localParticipantId } />
  133. : (
  134. <VideoMenu id = 'localVideoMenu'>
  135. <FlipLocalVideoButton />
  136. { isMobileBrowser()
  137. && <ConnectionStatusButton participantId = { _localParticipantId } />
  138. }
  139. </VideoMenu>
  140. );
  141. return (
  142. isMobileBrowser() || _showLocalVideoFlipButton
  143. ? <Popover
  144. content = { content }
  145. onPopoverClose = { this._onPopoverClose }
  146. onPopoverOpen = { this._onPopoverOpen }
  147. overflowDrawer = { _overflowDrawer }
  148. position = { _menuPosition }
  149. ref = { this.popoverRef }>
  150. {!_overflowDrawer && (
  151. <span
  152. className = 'popover-trigger local-video-menu-trigger'>
  153. {!isMobileBrowser() && <Icon
  154. ariaLabel = { t('dialog.localUserControls') }
  155. role = 'button'
  156. size = '1em'
  157. src = { IconMenuThumb }
  158. tabIndex = { 0 }
  159. title = { t('dialog.localUserControls') } />
  160. }
  161. </span>
  162. )}
  163. </Popover>
  164. : null
  165. );
  166. }
  167. _onPopoverOpen: () => void;
  168. /**
  169. * Disable and hide toolbox while context menu is open.
  170. *
  171. * @returns {void}
  172. */
  173. _onPopoverOpen() {
  174. this.props.dispatch(setParticipantContextMenuOpen(true));
  175. this.props.dispatch(hideToolboxOnTileView());
  176. }
  177. _onPopoverClose: () => void;
  178. /**
  179. * Render normal context menu next time popover dialog opens.
  180. *
  181. * @returns {void}
  182. */
  183. _onPopoverClose() {
  184. const { dispatch } = this.props;
  185. batch(() => {
  186. dispatch(setParticipantContextMenuOpen(false));
  187. dispatch(renderConnectionStatus(false));
  188. });
  189. }
  190. }
  191. /**
  192. * Maps (parts of) the Redux state to the associated {@code LocalVideoMenuTriggerButton}'s props.
  193. *
  194. * @param {Object} state - The Redux state.
  195. * @private
  196. * @returns {Props}
  197. */
  198. function _mapStateToProps(state) {
  199. const currentLayout = getCurrentLayout(state);
  200. const localParticipant = getLocalParticipant(state);
  201. const { disableLocalVideoFlip } = state['features/base/config'];
  202. const videoTrack = getLocalVideoTrack(state['features/base/tracks']);
  203. const { overflowDrawer } = state['features/toolbox'];
  204. const { showConnectionInfo } = state['features/base/connection'];
  205. let _menuPosition;
  206. switch (currentLayout) {
  207. case LAYOUTS.TILE_VIEW:
  208. _menuPosition = 'left-start';
  209. break;
  210. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  211. _menuPosition = 'left-end';
  212. break;
  213. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
  214. _menuPosition = 'top';
  215. break;
  216. default:
  217. _menuPosition = 'auto';
  218. }
  219. return {
  220. _menuPosition,
  221. _showLocalVideoFlipButton: !disableLocalVideoFlip && videoTrack?.videoType !== 'desktop',
  222. _overflowDrawer: overflowDrawer,
  223. _localParticipantId: localParticipant.id,
  224. _showConnectionInfo: showConnectionInfo
  225. };
  226. }
  227. export default translate(connect(_mapStateToProps)(LocalVideoMenuTriggerButton));