Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LocalVideoMenuTriggerButton.tsx 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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 { IconDotsHorizontal } 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. '& svg': {
  102. width: '18px',
  103. height: '18px'
  104. }
  105. },
  106. contextMenu: {
  107. position: 'relative' as const,
  108. marginTop: 0,
  109. right: 'auto',
  110. padding: '0',
  111. minWidth: '200px'
  112. },
  113. flipText: {
  114. marginLeft: '36px'
  115. }
  116. };
  117. };
  118. /**
  119. * React Component for displaying an icon associated with opening the
  120. * the video menu for the local participant.
  121. *
  122. * @augments {Component}
  123. */
  124. class LocalVideoMenuTriggerButton extends Component<IProps> {
  125. /**
  126. * Initializes a new LocalVideoMenuTriggerButton instance.
  127. *
  128. * @param {Object} props - The read-only React Component props with which
  129. * the new instance is to be initialized.
  130. */
  131. constructor(props: IProps) {
  132. super(props);
  133. this._onPopoverClose = this._onPopoverClose.bind(this);
  134. this._onPopoverOpen = this._onPopoverOpen.bind(this);
  135. }
  136. /**
  137. * Implements React's {@link Component#render()}.
  138. *
  139. * @inheritdoc
  140. * @returns {ReactElement}
  141. */
  142. render() {
  143. const {
  144. _localParticipantId,
  145. _menuPosition,
  146. _overflowDrawer,
  147. _showConnectionInfo,
  148. _showHideSelfViewButton,
  149. _showLocalVideoFlipButton,
  150. _showPinToStage,
  151. buttonVisible,
  152. classes,
  153. hidePopover,
  154. popoverVisible,
  155. t
  156. } = this.props;
  157. const content = _showConnectionInfo
  158. ? <ConnectionIndicatorContent participantId = { _localParticipantId } />
  159. : (
  160. <ContextMenu
  161. className = { classes.contextMenu }
  162. hidden = { false }
  163. inDrawer = { _overflowDrawer }>
  164. <ContextMenuItemGroup>
  165. { _showLocalVideoFlipButton
  166. && <FlipLocalVideoButton
  167. className = { _overflowDrawer ? classes.flipText : '' }
  168. onClick = { hidePopover } />
  169. }
  170. { _showHideSelfViewButton
  171. && <HideSelfViewVideoButton
  172. className = { _overflowDrawer ? classes.flipText : '' }
  173. onClick = { hidePopover } />
  174. }
  175. {
  176. _showPinToStage && <TogglePinToStageButton
  177. className = { _overflowDrawer ? classes.flipText : '' }
  178. noIcon = { true }
  179. onClick = { hidePopover }
  180. participantID = { _localParticipantId } />
  181. }
  182. { isMobileBrowser()
  183. && <ConnectionStatusButton participantId = { _localParticipantId } />
  184. }
  185. </ContextMenuItemGroup>
  186. </ContextMenu>
  187. );
  188. return (
  189. isMobileBrowser() || _showLocalVideoFlipButton || _showHideSelfViewButton
  190. ? <Popover
  191. content = { content }
  192. id = 'local-video-menu-trigger'
  193. onPopoverClose = { this._onPopoverClose }
  194. onPopoverOpen = { this._onPopoverOpen }
  195. overflowDrawer = { _overflowDrawer }
  196. position = { _menuPosition }
  197. visible = { popoverVisible }>
  198. {!_overflowDrawer && buttonVisible && !isMobileBrowser() && (
  199. <Button
  200. accessibilityLabel = { t('dialog.localUserControls') }
  201. className = { classes.triggerButton }
  202. icon = { IconDotsHorizontal }
  203. size = 'small' />
  204. )}
  205. </Popover>
  206. : null
  207. );
  208. }
  209. /**
  210. * Disable and hide toolbox while context menu is open.
  211. *
  212. * @returns {void}
  213. */
  214. _onPopoverOpen() {
  215. const { dispatch, showPopover } = this.props;
  216. showPopover();
  217. dispatch(setParticipantContextMenuOpen(true));
  218. }
  219. /**
  220. * Render normal context menu next time popover dialog opens.
  221. *
  222. * @returns {void}
  223. */
  224. _onPopoverClose() {
  225. const { hidePopover, dispatch } = this.props;
  226. hidePopover();
  227. batch(() => {
  228. dispatch(setParticipantContextMenuOpen(false));
  229. dispatch(renderConnectionStatus(false));
  230. });
  231. }
  232. }
  233. /**
  234. * Maps (parts of) the Redux state to the associated {@code LocalVideoMenuTriggerButton}'s props.
  235. *
  236. * @param {Object} state - The Redux state.
  237. * @param {Object} ownProps - The own props of the component.
  238. * @private
  239. * @returns {IProps}
  240. */
  241. function _mapStateToProps(state: IReduxState, ownProps: Partial<IProps>) {
  242. const { thumbnailType } = ownProps;
  243. const localParticipant = getLocalParticipant(state);
  244. const { disableLocalVideoFlip, disableSelfViewSettings } = state['features/base/config'];
  245. const videoTrack = getLocalVideoTrack(state['features/base/tracks']);
  246. const { overflowDrawer } = state['features/toolbox'];
  247. const { showConnectionInfo } = state['features/base/connection'];
  248. const showHideSelfViewButton = !disableSelfViewSettings && !getHideSelfView(state);
  249. let _menuPosition;
  250. switch (thumbnailType) {
  251. case THUMBNAIL_TYPE.TILE:
  252. _menuPosition = 'left-start';
  253. break;
  254. case THUMBNAIL_TYPE.VERTICAL:
  255. _menuPosition = 'left-start';
  256. break;
  257. case THUMBNAIL_TYPE.HORIZONTAL:
  258. _menuPosition = 'top-start';
  259. break;
  260. default:
  261. _menuPosition = 'auto';
  262. }
  263. return {
  264. _menuPosition,
  265. _showLocalVideoFlipButton: !disableLocalVideoFlip && videoTrack?.videoType !== 'desktop',
  266. _showHideSelfViewButton: showHideSelfViewButton,
  267. _overflowDrawer: overflowDrawer,
  268. _localParticipantId: localParticipant?.id ?? '',
  269. _showConnectionInfo: Boolean(showConnectionInfo),
  270. _showPinToStage: isStageFilmstripAvailable(state)
  271. };
  272. }
  273. export default translate(connect(_mapStateToProps)(withStyles(styles)(LocalVideoMenuTriggerButton)));