Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LocalVideoMenuTriggerButton.tsx 9.4KB

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