You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LocalVideoMenuTriggerButton.tsx 9.5KB

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. 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. headingLabel = { t('dialog.localUserControls') }
  192. id = 'local-video-menu-trigger'
  193. onPopoverClose = { this._onPopoverClose }
  194. onPopoverOpen = { this._onPopoverOpen }
  195. overflowDrawer = { _overflowDrawer }
  196. position = { _menuPosition }
  197. visible = { popoverVisible }>
  198. {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)));