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

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