選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LocalVideoMenuTriggerButton.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. * Hides popover.
  35. */
  36. hidePopover: Function,
  37. /**
  38. * Whether the popover is visible or not.
  39. */
  40. popoverVisible: boolean,
  41. /**
  42. * Shows popover.
  43. */
  44. showPopover: Function,
  45. /**
  46. * The id of the local participant.
  47. */
  48. _localParticipantId: string,
  49. /**
  50. * The position relative to the trigger the local video menu should display
  51. * from. Valid values are those supported by AtlasKit
  52. * {@code InlineDialog}.
  53. */
  54. _menuPosition: string,
  55. /**
  56. * Whether to display the Popover as a drawer.
  57. */
  58. _overflowDrawer: boolean,
  59. /**
  60. * Whether to render the connection info pane.
  61. */
  62. _showConnectionInfo: boolean,
  63. /**
  64. * Shows/hides the local video flip button.
  65. */
  66. _showLocalVideoFlipButton: boolean,
  67. /**
  68. * Invoked to obtain translated strings.
  69. */
  70. t: Function
  71. };
  72. /**
  73. * React Component for displaying an icon associated with opening the
  74. * the video menu for the local participant.
  75. *
  76. * @augments {Component}
  77. */
  78. class LocalVideoMenuTriggerButton extends Component<Props> {
  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._onPopoverClose = this._onPopoverClose.bind(this);
  88. this._onPopoverOpen = this._onPopoverOpen.bind(this);
  89. }
  90. /**
  91. * Implements React's {@link Component#render()}.
  92. *
  93. * @inheritdoc
  94. * @returns {ReactElement}
  95. */
  96. render() {
  97. const {
  98. _localParticipantId,
  99. _menuPosition,
  100. _showConnectionInfo,
  101. _overflowDrawer,
  102. _showLocalVideoFlipButton,
  103. hidePopover,
  104. popoverVisible,
  105. t
  106. } = this.props;
  107. const content = _showConnectionInfo
  108. ? <ConnectionIndicatorContent participantId = { _localParticipantId } />
  109. : (
  110. <VideoMenu id = 'localVideoMenu'>
  111. <FlipLocalVideoButton onClick = { hidePopover } />
  112. { isMobileBrowser()
  113. && <ConnectionStatusButton participantId = { _localParticipantId } />
  114. }
  115. </VideoMenu>
  116. );
  117. return (
  118. isMobileBrowser() || _showLocalVideoFlipButton
  119. ? <Popover
  120. content = { content }
  121. id = 'local-video-menu-trigger'
  122. onPopoverClose = { this._onPopoverClose }
  123. onPopoverOpen = { this._onPopoverOpen }
  124. overflowDrawer = { _overflowDrawer }
  125. position = { _menuPosition }
  126. visible = { popoverVisible }>
  127. {!_overflowDrawer && (
  128. <span
  129. className = 'popover-trigger local-video-menu-trigger'>
  130. {!isMobileBrowser() && <Icon
  131. ariaLabel = { t('dialog.localUserControls') }
  132. role = 'button'
  133. size = '1.4em'
  134. src = { IconMenuThumb }
  135. tabIndex = { 0 }
  136. title = { t('dialog.localUserControls') } />
  137. }
  138. </span>
  139. )}
  140. </Popover>
  141. : null
  142. );
  143. }
  144. _onPopoverOpen: () => void;
  145. /**
  146. * Disable and hide toolbox while context menu is open.
  147. *
  148. * @returns {void}
  149. */
  150. _onPopoverOpen() {
  151. const { dispatch, showPopover } = this.props;
  152. showPopover();
  153. dispatch(setParticipantContextMenuOpen(true));
  154. }
  155. _onPopoverClose: () => void;
  156. /**
  157. * Render normal context menu next time popover dialog opens.
  158. *
  159. * @returns {void}
  160. */
  161. _onPopoverClose() {
  162. const { hidePopover, dispatch } = this.props;
  163. hidePopover();
  164. batch(() => {
  165. dispatch(setParticipantContextMenuOpen(false));
  166. dispatch(renderConnectionStatus(false));
  167. });
  168. }
  169. }
  170. /**
  171. * Maps (parts of) the Redux state to the associated {@code LocalVideoMenuTriggerButton}'s props.
  172. *
  173. * @param {Object} state - The Redux state.
  174. * @private
  175. * @returns {Props}
  176. */
  177. function _mapStateToProps(state) {
  178. const currentLayout = getCurrentLayout(state);
  179. const localParticipant = getLocalParticipant(state);
  180. const { disableLocalVideoFlip } = state['features/base/config'];
  181. const videoTrack = getLocalVideoTrack(state['features/base/tracks']);
  182. const { overflowDrawer } = state['features/toolbox'];
  183. const { showConnectionInfo } = state['features/base/connection'];
  184. let _menuPosition;
  185. switch (currentLayout) {
  186. case LAYOUTS.TILE_VIEW:
  187. _menuPosition = 'left-start';
  188. break;
  189. case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
  190. _menuPosition = 'left-end';
  191. break;
  192. case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
  193. _menuPosition = 'top';
  194. break;
  195. default:
  196. _menuPosition = 'auto';
  197. }
  198. return {
  199. _menuPosition,
  200. _showLocalVideoFlipButton: !disableLocalVideoFlip && videoTrack?.videoType !== 'desktop',
  201. _overflowDrawer: overflowDrawer,
  202. _localParticipantId: localParticipant.id,
  203. _showConnectionInfo: showConnectionInfo
  204. };
  205. }
  206. export default translate(connect(_mapStateToProps)(LocalVideoMenuTriggerButton));