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

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