Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LocalVideoMenuTriggerButton.tsx 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* eslint-disable lines-around-comment */
  2. import { withStyles } from '@mui/styles';
  3. import React, { Component } from 'react';
  4. import { WithTranslation } from 'react-i18next';
  5. import { batch, connect } from 'react-redux';
  6. import { IReduxState } from '../../../app/types';
  7. import { isMobileBrowser } from '../../../base/environment/utils';
  8. import { translate } from '../../../base/i18n/functions';
  9. import { IconHorizontalPoints } from '../../../base/icons/svg';
  10. import { getLocalParticipant } from '../../../base/participants/functions';
  11. import Popover from '../../../base/popover/components/Popover.web';
  12. import { setParticipantContextMenuOpen } from '../../../base/responsive-ui/actions';
  13. import { getHideSelfView } from '../../../base/settings/functions.web';
  14. import { getLocalVideoTrack } from '../../../base/tracks/functions';
  15. import Button from '../../../base/ui/components/web/Button';
  16. import ContextMenu from '../../../base/ui/components/web/ContextMenu';
  17. import ContextMenuItemGroup from '../../../base/ui/components/web/ContextMenuItemGroup';
  18. // @ts-ignore
  19. import ConnectionIndicatorContent from '../../../connection-indicator/components/web/ConnectionIndicatorContent';
  20. import { THUMBNAIL_TYPE } from '../../../filmstrip/constants';
  21. // @ts-ignore
  22. import { isStageFilmstripAvailable } from '../../../filmstrip/functions.web';
  23. // @ts-ignore
  24. import { renderConnectionStatus } from '../../actions.web';
  25. // @ts-ignore
  26. import ConnectionStatusButton from './ConnectionStatusButton';
  27. // @ts-ignore
  28. import FlipLocalVideoButton from './FlipLocalVideoButton';
  29. // @ts-ignore
  30. import HideSelfViewVideoButton from './HideSelfViewVideoButton';
  31. // @ts-ignore
  32. import TogglePinToStageButton from './TogglePinToStageButton';
  33. /**
  34. * The type of the React {@code Component} props of
  35. * {@link LocalVideoMenuTriggerButton}.
  36. */
  37. interface IProps extends WithTranslation {
  38. /**
  39. * The id of the local participant.
  40. */
  41. _localParticipantId: string;
  42. /**
  43. * The position relative to the trigger the local video menu should display
  44. * from.
  45. */
  46. _menuPosition: string;
  47. /**
  48. * Whether to display the Popover as a drawer.
  49. */
  50. _overflowDrawer: boolean;
  51. /**
  52. * Whether to render the connection info pane.
  53. */
  54. _showConnectionInfo: boolean;
  55. /**
  56. * Whether to render the hide self view button.
  57. */
  58. _showHideSelfViewButton: boolean;
  59. /**
  60. * Shows/hides the local video flip button.
  61. */
  62. _showLocalVideoFlipButton: boolean;
  63. /**
  64. * Whether to render the pin to stage button.
  65. */
  66. _showPinToStage: boolean;
  67. /**
  68. * Whether or not the button should be visible.
  69. */
  70. buttonVisible: boolean;
  71. /**
  72. * An object containing the CSS classes.
  73. */
  74. classes: any;
  75. /**
  76. * The redux dispatch function.
  77. */
  78. dispatch: Function;
  79. /**
  80. * Hides popover.
  81. */
  82. hidePopover: Function;
  83. /**
  84. * Whether the popover is visible or not.
  85. */
  86. popoverVisible: boolean;
  87. /**
  88. * Shows popover.
  89. */
  90. showPopover: Function;
  91. /**
  92. * The type of the thumbnail.
  93. */
  94. thumbnailType: string;
  95. }
  96. const styles = () => {
  97. return {
  98. triggerButton: {
  99. padding: '3px !important',
  100. borderRadius: '4px'
  101. },
  102. contextMenu: {
  103. position: 'relative' as const,
  104. marginTop: 0,
  105. right: 'auto',
  106. padding: '0',
  107. minWidth: '200px'
  108. },
  109. flipText: {
  110. marginLeft: '36px'
  111. }
  112. };
  113. };
  114. /**
  115. * React Component for displaying an icon associated with opening the
  116. * the video menu for the local participant.
  117. *
  118. * @augments {Component}
  119. */
  120. class LocalVideoMenuTriggerButton extends Component<IProps> {
  121. /**
  122. * Initializes a new LocalVideoMenuTriggerButton instance.
  123. *
  124. * @param {Object} props - The read-only React Component props with which
  125. * the new instance is to be initialized.
  126. */
  127. constructor(props: IProps) {
  128. super(props);
  129. this._onPopoverClose = this._onPopoverClose.bind(this);
  130. this._onPopoverOpen = this._onPopoverOpen.bind(this);
  131. }
  132. /**
  133. * Implements React's {@link Component#render()}.
  134. *
  135. * @inheritdoc
  136. * @returns {ReactElement}
  137. */
  138. render() {
  139. const {
  140. _localParticipantId,
  141. _menuPosition,
  142. _overflowDrawer,
  143. _showConnectionInfo,
  144. _showHideSelfViewButton,
  145. _showLocalVideoFlipButton,
  146. _showPinToStage,
  147. buttonVisible,
  148. classes,
  149. hidePopover,
  150. popoverVisible,
  151. t
  152. } = this.props;
  153. const content = _showConnectionInfo
  154. ? <ConnectionIndicatorContent participantId = { _localParticipantId } />
  155. : (
  156. <ContextMenu
  157. className = { classes.contextMenu }
  158. hidden = { false }
  159. inDrawer = { _overflowDrawer }>
  160. <ContextMenuItemGroup>
  161. { _showLocalVideoFlipButton
  162. && <FlipLocalVideoButton
  163. className = { _overflowDrawer ? classes.flipText : '' }
  164. onClick = { hidePopover } />
  165. }
  166. { _showHideSelfViewButton
  167. && <HideSelfViewVideoButton
  168. className = { _overflowDrawer ? classes.flipText : '' }
  169. onClick = { hidePopover } />
  170. }
  171. {
  172. _showPinToStage && <TogglePinToStageButton
  173. className = { _overflowDrawer ? classes.flipText : '' }
  174. noIcon = { true }
  175. onClick = { hidePopover }
  176. participantID = { _localParticipantId } />
  177. }
  178. { isMobileBrowser()
  179. && <ConnectionStatusButton participantId = { _localParticipantId } />
  180. }
  181. </ContextMenuItemGroup>
  182. </ContextMenu>
  183. );
  184. return (
  185. isMobileBrowser() || _showLocalVideoFlipButton || _showHideSelfViewButton
  186. ? <Popover
  187. content = { content }
  188. id = 'local-video-menu-trigger'
  189. onPopoverClose = { this._onPopoverClose }
  190. onPopoverOpen = { this._onPopoverOpen }
  191. overflowDrawer = { _overflowDrawer }
  192. position = { _menuPosition }
  193. visible = { popoverVisible }>
  194. {!_overflowDrawer && buttonVisible && !isMobileBrowser() && (
  195. <Button
  196. accessibilityLabel = { t('dialog.localUserControls') }
  197. className = { classes.triggerButton }
  198. icon = { IconHorizontalPoints }
  199. size = 'small' />
  200. )}
  201. </Popover>
  202. : null
  203. );
  204. }
  205. /**
  206. * Disable and hide toolbox while context menu is open.
  207. *
  208. * @returns {void}
  209. */
  210. _onPopoverOpen() {
  211. const { dispatch, showPopover } = this.props;
  212. showPopover();
  213. dispatch(setParticipantContextMenuOpen(true));
  214. }
  215. /**
  216. * Render normal context menu next time popover dialog opens.
  217. *
  218. * @returns {void}
  219. */
  220. _onPopoverClose() {
  221. const { hidePopover, dispatch } = this.props;
  222. hidePopover();
  223. batch(() => {
  224. dispatch(setParticipantContextMenuOpen(false));
  225. dispatch(renderConnectionStatus(false));
  226. });
  227. }
  228. }
  229. /**
  230. * Maps (parts of) the Redux state to the associated {@code LocalVideoMenuTriggerButton}'s props.
  231. *
  232. * @param {Object} state - The Redux state.
  233. * @param {Object} ownProps - The own props of the component.
  234. * @private
  235. * @returns {IProps}
  236. */
  237. function _mapStateToProps(state: IReduxState, ownProps: Partial<IProps>) {
  238. const { thumbnailType } = ownProps;
  239. const localParticipant = getLocalParticipant(state);
  240. const { disableLocalVideoFlip, disableSelfViewSettings } = state['features/base/config'];
  241. const videoTrack = getLocalVideoTrack(state['features/base/tracks']);
  242. const { overflowDrawer } = state['features/toolbox'];
  243. const { showConnectionInfo } = state['features/base/connection'];
  244. const showHideSelfViewButton = !disableSelfViewSettings && !getHideSelfView(state);
  245. let _menuPosition;
  246. switch (thumbnailType) {
  247. case THUMBNAIL_TYPE.TILE:
  248. _menuPosition = 'left-start';
  249. break;
  250. case THUMBNAIL_TYPE.VERTICAL:
  251. _menuPosition = 'left-start';
  252. break;
  253. case THUMBNAIL_TYPE.HORIZONTAL:
  254. _menuPosition = 'top-start';
  255. break;
  256. default:
  257. _menuPosition = 'auto';
  258. }
  259. return {
  260. _menuPosition,
  261. _showLocalVideoFlipButton: !disableLocalVideoFlip && videoTrack?.videoType !== 'desktop',
  262. _showHideSelfViewButton: showHideSelfViewButton,
  263. _overflowDrawer: overflowDrawer,
  264. _localParticipantId: localParticipant?.id ?? '',
  265. _showConnectionInfo: Boolean(showConnectionInfo),
  266. _showPinToStage: isStageFilmstripAvailable(state)
  267. };
  268. }
  269. export default translate(connect(_mapStateToProps)(withStyles(styles)(LocalVideoMenuTriggerButton)));