您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LocalVideoMenuTriggerButton.tsx 9.4KB

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