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.1KB

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