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

LocalVideoMenuTriggerButton.tsx 11KB

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