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.9KB

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