Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Toolbox.tsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import React, { useCallback, useEffect, useRef } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useDispatch, useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IReduxState } from '../../../app/types';
  6. import { isMobileBrowser } from '../../../base/environment/utils';
  7. import { getLocalParticipant, isLocalParticipantModerator } from '../../../base/participants/functions';
  8. import ContextMenu from '../../../base/ui/components/web/ContextMenu';
  9. import { isReactionsButtonEnabled, shouldDisplayReactionsButtons } from '../../../reactions/functions.web';
  10. import { isTranscribing } from '../../../transcribing/functions';
  11. import {
  12. setHangupMenuVisible,
  13. setOverflowMenuVisible,
  14. setToolbarHovered,
  15. showToolbox
  16. } from '../../actions.web';
  17. import {
  18. getJwtDisabledButtons,
  19. getVisibleButtons,
  20. isButtonEnabled,
  21. isToolboxVisible
  22. } from '../../functions.web';
  23. import { useKeyboardShortcuts, useToolboxButtons } from '../../hooks.web';
  24. import { IToolboxButton } from '../../types';
  25. import HangupButton from '../HangupButton';
  26. import { EndConferenceButton } from './EndConferenceButton';
  27. import HangupMenuButton from './HangupMenuButton';
  28. import { LeaveConferenceButton } from './LeaveConferenceButton';
  29. import OverflowMenuButton from './OverflowMenuButton';
  30. import Separator from './Separator';
  31. /**
  32. * The type of the React {@code Component} props of {@link Toolbox}.
  33. */
  34. interface IProps {
  35. /**
  36. * Explicitly passed array with the buttons which this Toolbox should display.
  37. */
  38. toolbarButtons?: Array<string>;
  39. }
  40. const useStyles = makeStyles()(() => {
  41. return {
  42. contextMenu: {
  43. position: 'relative',
  44. right: 'auto',
  45. margin: 0,
  46. marginBottom: '8px',
  47. maxHeight: 'calc(100dvh - 100px)',
  48. minWidth: '240px'
  49. },
  50. hangupMenu: {
  51. position: 'relative',
  52. right: 'auto',
  53. display: 'flex',
  54. flexDirection: 'column',
  55. rowGap: '8px',
  56. margin: 0,
  57. padding: '16px',
  58. marginBottom: '4px'
  59. }
  60. };
  61. });
  62. /**
  63. * A component that renders the main toolbar.
  64. *
  65. * @param {IProps} props - The props of the component.
  66. * @returns {ReactElement}
  67. */
  68. export default function Toolbox({
  69. toolbarButtons
  70. }: IProps) {
  71. const { classes, cx } = useStyles();
  72. const { t } = useTranslation();
  73. const dispatch = useDispatch();
  74. const _toolboxRef = useRef<HTMLDivElement>(null);
  75. const conference = useSelector((state: IReduxState) => state['features/base/conference'].conference);
  76. const isNarrowLayout = useSelector((state: IReduxState) => state['features/base/responsive-ui'].isNarrowLayout);
  77. const clientWidth = useSelector((state: IReduxState) => state['features/base/responsive-ui'].clientWidth);
  78. const isModerator = useSelector(isLocalParticipantModerator);
  79. const customToolbarButtons = useSelector(
  80. (state: IReduxState) => state['features/base/config'].customToolbarButtons);
  81. const iAmRecorder = useSelector((state: IReduxState) => state['features/base/config'].iAmRecorder);
  82. const iAmSipGateway = useSelector((state: IReduxState) => state['features/base/config'].iAmSipGateway);
  83. const overflowDrawer = useSelector((state: IReduxState) => state['features/toolbox'].overflowDrawer);
  84. const shiftUp = useSelector((state: IReduxState) => state['features/toolbox'].shiftUp);
  85. const overflowMenuVisible = useSelector((state: IReduxState) => state['features/toolbox'].overflowMenuVisible);
  86. const hangupMenuVisible = useSelector((state: IReduxState) => state['features/toolbox'].hangupMenuVisible);
  87. const buttonsWithNotifyClick
  88. = useSelector((state: IReduxState) => state['features/toolbox'].buttonsWithNotifyClick);
  89. const reduxToolbarButtons = useSelector((state: IReduxState) => state['features/toolbox'].toolbarButtons);
  90. const toolbarButtonsToUse = toolbarButtons || reduxToolbarButtons;
  91. const chatOpen = useSelector((state: IReduxState) => state['features/chat'].isOpen);
  92. const isDialogVisible = useSelector((state: IReduxState) => Boolean(state['features/base/dialog'].component));
  93. const jwt = useSelector((state: IReduxState) => state['features/base/jwt'].jwt);
  94. const localParticipant = useSelector(getLocalParticipant);
  95. const transcribing = useSelector(isTranscribing);
  96. // Do not convert to selector, it returns new array and will cause re-rendering of toolbox on every action.
  97. const jwtDisabledButtons = getJwtDisabledButtons(transcribing, isModerator, jwt, localParticipant?.features);
  98. const reactionsButtonEnabled = useSelector(isReactionsButtonEnabled);
  99. const _shouldDisplayReactionsButtons = useSelector(shouldDisplayReactionsButtons);
  100. const toolbarVisible = useSelector(isToolboxVisible);
  101. const mainToolbarButtonsThresholds
  102. = useSelector((state: IReduxState) => state['features/toolbox'].mainToolbarButtonsThresholds);
  103. const allButtons = useToolboxButtons(customToolbarButtons);
  104. useKeyboardShortcuts(toolbarButtonsToUse);
  105. useEffect(() => {
  106. if (!toolbarVisible) {
  107. if (document.activeElement instanceof HTMLElement
  108. && _toolboxRef.current?.contains(document.activeElement)) {
  109. document.activeElement.blur();
  110. }
  111. }
  112. }, [ toolbarVisible ]);
  113. /**
  114. * Sets the visibility of the hangup menu.
  115. *
  116. * @param {boolean} visible - Whether or not the hangup menu should be
  117. * displayed.
  118. * @private
  119. * @returns {void}
  120. */
  121. const onSetHangupVisible = useCallback((visible: boolean) => {
  122. dispatch(setHangupMenuVisible(visible));
  123. dispatch(setToolbarHovered(visible));
  124. }, [ dispatch ]);
  125. /**
  126. * Sets the visibility of the overflow menu.
  127. *
  128. * @param {boolean} visible - Whether or not the overflow menu should be
  129. * displayed.
  130. * @private
  131. * @returns {void}
  132. */
  133. const onSetOverflowVisible = useCallback((visible: boolean) => {
  134. dispatch(setOverflowMenuVisible(visible));
  135. dispatch(setToolbarHovered(visible));
  136. }, [ dispatch ]);
  137. useEffect(() => {
  138. if (hangupMenuVisible && !toolbarVisible) {
  139. onSetHangupVisible(false);
  140. dispatch(setToolbarHovered(false));
  141. }
  142. }, [ dispatch, hangupMenuVisible, toolbarVisible, onSetHangupVisible ]);
  143. useEffect(() => {
  144. if (overflowMenuVisible && isDialogVisible) {
  145. onSetOverflowVisible(false);
  146. dispatch(setToolbarHovered(false));
  147. }
  148. }, [ dispatch, overflowMenuVisible, isDialogVisible, onSetOverflowVisible ]);
  149. /**
  150. * Key handler for overflow/hangup menus.
  151. *
  152. * @param {KeyboardEvent} e - Esc key click to close the popup.
  153. * @returns {void}
  154. */
  155. const onEscKey = useCallback((e?: React.KeyboardEvent) => {
  156. if (e?.key === 'Escape') {
  157. e?.stopPropagation();
  158. hangupMenuVisible && dispatch(setHangupMenuVisible(false));
  159. overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
  160. }
  161. }, [ dispatch, hangupMenuVisible, overflowMenuVisible ]);
  162. /**
  163. * Dispatches an action signaling the toolbar is not being hovered.
  164. *
  165. * @private
  166. * @returns {void}
  167. */
  168. const onMouseOut = useCallback(() => {
  169. !overflowMenuVisible && dispatch(setToolbarHovered(false));
  170. }, [ dispatch, overflowMenuVisible ]);
  171. /**
  172. * Dispatches an action signaling the toolbar is being hovered.
  173. *
  174. * @private
  175. * @returns {void}
  176. */
  177. const onMouseOver = useCallback(() => {
  178. dispatch(setToolbarHovered(true));
  179. }, [ dispatch ]);
  180. /**
  181. * Toggle the toolbar visibility when tabbing into it.
  182. *
  183. * @returns {void}
  184. */
  185. const onTabIn = useCallback(() => {
  186. if (!toolbarVisible) {
  187. dispatch(showToolbox());
  188. }
  189. }, [ toolbarVisible, dispatch ]);
  190. if (iAmRecorder || iAmSipGateway) {
  191. return null;
  192. }
  193. const endConferenceSupported = Boolean(conference?.isEndConferenceSupported() && isModerator);
  194. const isMobile = isMobileBrowser();
  195. const rootClassNames = `new-toolbox ${toolbarVisible ? 'visible' : ''} ${
  196. toolbarButtonsToUse.length ? '' : 'no-buttons'} ${chatOpen ? 'shift-right' : ''}`;
  197. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  198. const containerClassName = `toolbox-content${isMobile || isNarrowLayout ? ' toolbox-content-mobile' : ''}`;
  199. const { mainMenuButtons, overflowMenuButtons } = getVisibleButtons({
  200. allButtons,
  201. buttonsWithNotifyClick,
  202. toolbarButtons: toolbarButtonsToUse,
  203. clientWidth,
  204. jwtDisabledButtons,
  205. mainToolbarButtonsThresholds
  206. });
  207. const raiseHandInOverflowMenu = overflowMenuButtons.some(({ key }) => key === 'raisehand');
  208. const showReactionsInOverflowMenu = _shouldDisplayReactionsButtons
  209. && (
  210. (!reactionsButtonEnabled && (raiseHandInOverflowMenu || isNarrowLayout || isMobile))
  211. || overflowMenuButtons.some(({ key }) => key === 'reactions'));
  212. const showRaiseHandInReactionsMenu = showReactionsInOverflowMenu && raiseHandInOverflowMenu;
  213. return (
  214. <div
  215. className = { cx(rootClassNames, shiftUp && 'shift-up') }
  216. id = 'new-toolbox'>
  217. <div className = { containerClassName }>
  218. <div
  219. className = 'toolbox-content-wrapper'
  220. onFocus = { onTabIn }
  221. { ...(isMobile ? {} : {
  222. onMouseOut,
  223. onMouseOver
  224. }) }>
  225. <div
  226. className = 'toolbox-content-items'
  227. ref = { _toolboxRef }>
  228. {mainMenuButtons.map(({ Content, key, ...rest }) => Content !== Separator && (
  229. <Content
  230. { ...rest }
  231. buttonKey = { key }
  232. key = { key } />))}
  233. {Boolean(overflowMenuButtons.length) && (
  234. <OverflowMenuButton
  235. ariaControls = 'overflow-menu'
  236. buttons = { overflowMenuButtons.reduce<Array<IToolboxButton[]>>((acc, val) => {
  237. if (val.key === 'reactions' && showReactionsInOverflowMenu) {
  238. return acc;
  239. }
  240. if (val.key === 'raisehand' && showRaiseHandInReactionsMenu) {
  241. return acc;
  242. }
  243. if (acc.length) {
  244. const prev = acc[acc.length - 1];
  245. const group = prev[prev.length - 1].group;
  246. if (group === val.group) {
  247. prev.push(val);
  248. } else {
  249. acc.push([ val ]);
  250. }
  251. } else {
  252. acc.push([ val ]);
  253. }
  254. return acc;
  255. }, []) }
  256. isOpen = { overflowMenuVisible }
  257. key = 'overflow-menu'
  258. onToolboxEscKey = { onEscKey }
  259. onVisibilityChange = { onSetOverflowVisible }
  260. showRaiseHandInReactionsMenu = { showRaiseHandInReactionsMenu }
  261. showReactionsMenu = { showReactionsInOverflowMenu } />
  262. )}
  263. {isButtonEnabled('hangup', toolbarButtonsToUse) && (
  264. endConferenceSupported
  265. ? <HangupMenuButton
  266. ariaControls = 'hangup-menu'
  267. isOpen = { hangupMenuVisible }
  268. key = 'hangup-menu'
  269. notifyMode = { buttonsWithNotifyClick?.get('hangup-menu') }
  270. onVisibilityChange = { onSetHangupVisible }>
  271. <ContextMenu
  272. accessibilityLabel = { t(toolbarAccLabel) }
  273. className = { classes.hangupMenu }
  274. hidden = { false }
  275. inDrawer = { overflowDrawer }
  276. onKeyDown = { onEscKey }>
  277. <EndConferenceButton
  278. buttonKey = 'end-meeting'
  279. notifyMode = { buttonsWithNotifyClick?.get('end-meeting') } />
  280. <LeaveConferenceButton
  281. buttonKey = 'hangup'
  282. notifyMode = { buttonsWithNotifyClick?.get('hangup') } />
  283. </ContextMenu>
  284. </HangupMenuButton>
  285. : <HangupButton
  286. buttonKey = 'hangup'
  287. customClass = 'hangup-button'
  288. key = 'hangup-button'
  289. notifyMode = { buttonsWithNotifyClick.get('hangup') }
  290. visible = { isButtonEnabled('hangup', toolbarButtonsToUse) } />
  291. )}
  292. </div>
  293. </div>
  294. </div>
  295. </div>
  296. );
  297. }