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.

Toolbox.tsx 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. import { withStyles } from '@mui/styles';
  2. import clsx from 'clsx';
  3. import React, { Component, RefObject } from 'react';
  4. import { WithTranslation } from 'react-i18next';
  5. import { batch, connect } from 'react-redux';
  6. import { isSpeakerStatsDisabled } from '../../../../features/speaker-stats/functions';
  7. import { ACTION_SHORTCUT_TRIGGERED, createShortcutEvent } from '../../../analytics/AnalyticsEvents';
  8. import { sendAnalytics } from '../../../analytics/functions';
  9. import { IReduxState, IStore } from '../../../app/types';
  10. import { VISITORS_MODE_BUTTONS } from '../../../base/config/constants';
  11. import {
  12. getButtonsWithNotifyClick,
  13. getToolbarButtons,
  14. isToolbarButtonEnabled
  15. } from '../../../base/config/functions.web';
  16. import { toggleDialog } from '../../../base/dialog/actions';
  17. import { isMobileBrowser } from '../../../base/environment/utils';
  18. import { translate } from '../../../base/i18n/functions';
  19. import JitsiMeetJS from '../../../base/lib-jitsi-meet';
  20. import {
  21. raiseHand
  22. } from '../../../base/participants/actions';
  23. import {
  24. getLocalParticipant,
  25. hasRaisedHand,
  26. isLocalParticipantModerator
  27. } from '../../../base/participants/functions';
  28. import ContextMenu from '../../../base/ui/components/web/ContextMenu';
  29. import { toggleChat } from '../../../chat/actions.web';
  30. import { setGifMenuVisibility } from '../../../gifs/actions';
  31. import { isGifEnabled } from '../../../gifs/functions.web';
  32. import { registerShortcut, unregisterShortcut } from '../../../keyboard-shortcuts/actions';
  33. import {
  34. close as closeParticipantsPane,
  35. open as openParticipantsPane
  36. } from '../../../participants-pane/actions.web';
  37. import { getParticipantsPaneOpen } from '../../../participants-pane/functions';
  38. import {
  39. addReactionToBuffer,
  40. toggleReactionsMenuVisibility
  41. } from '../../../reactions/actions.web';
  42. import { REACTIONS } from '../../../reactions/constants';
  43. import { isReactionsButtonEnabled, isReactionsEnabled } from '../../../reactions/functions.web';
  44. import {
  45. startScreenShareFlow
  46. } from '../../../screen-share/actions.web';
  47. import {
  48. isScreenVideoShared
  49. } from '../../../screen-share/functions';
  50. import SpeakerStats from '../../../speaker-stats/components/web/SpeakerStats';
  51. import { toggleTileView } from '../../../video-layout/actions.web';
  52. import { shouldDisplayTileView } from '../../../video-layout/functions.web';
  53. import VideoQualityDialog from '../../../video-quality/components/VideoQualityDialog.web';
  54. import { iAmVisitor } from '../../../visitors/functions';
  55. import {
  56. setFullScreen,
  57. setHangupMenuVisible,
  58. setOverflowMenuVisible,
  59. setToolbarHovered,
  60. showToolbox
  61. } from '../../actions.web';
  62. import { NOTIFY_CLICK_MODE, NOT_APPLICABLE, THRESHOLDS } from '../../constants';
  63. import {
  64. getAllToolboxButtons,
  65. getJwtDisabledButtons,
  66. isDesktopShareButtonDisabled,
  67. isToolboxVisible
  68. } from '../../functions.web';
  69. import { IToolboxButton } from '../../types';
  70. import HangupButton from '../HangupButton';
  71. import { EndConferenceButton } from './EndConferenceButton';
  72. import HangupMenuButton from './HangupMenuButton';
  73. import { LeaveConferenceButton } from './LeaveConferenceButton';
  74. import OverflowMenuButton from './OverflowMenuButton';
  75. import Separator from './Separator';
  76. /**
  77. * The type of the React {@code Component} props of {@link Toolbox}.
  78. */
  79. interface IProps extends WithTranslation {
  80. /**
  81. * Toolbar buttons which have their click exposed through the API.
  82. */
  83. _buttonsWithNotifyClick?: Array<string | {
  84. key: string;
  85. preventExecution: boolean;
  86. }>;
  87. /**
  88. * Whether or not the chat feature is currently displayed.
  89. */
  90. _chatOpen: boolean;
  91. /**
  92. * The width of the client.
  93. */
  94. _clientWidth: number;
  95. /**
  96. * Custom Toolbar buttons.
  97. */
  98. _customToolbarButtons?: Array<{ icon: string; id: string; text: string; }>;
  99. /**
  100. * Whether or not screensharing button is disabled.
  101. */
  102. _desktopSharingButtonDisabled: boolean;
  103. /**
  104. * Whether or not screensharing is initialized.
  105. */
  106. _desktopSharingEnabled: boolean;
  107. /**
  108. * Whether or not a dialog is displayed.
  109. */
  110. _dialog: boolean;
  111. /**
  112. * Whether or not the toolbox is disabled. It is for recorders.
  113. */
  114. _disabled: boolean;
  115. /**
  116. * Whether the end conference feature is supported.
  117. */
  118. _endConferenceSupported: boolean;
  119. /**
  120. * Whether or not the app is currently in full screen.
  121. */
  122. _fullScreen?: boolean;
  123. /**
  124. * Whether or not the GIFs feature is enabled.
  125. */
  126. _gifsEnabled: boolean;
  127. /**
  128. * Whether the hangup menu is visible.
  129. */
  130. _hangupMenuVisible: boolean;
  131. /**
  132. * Whether or not the app is running in mobile browser.
  133. */
  134. _isMobile: boolean;
  135. /**
  136. * Whether we are in narrow layout mode.
  137. */
  138. _isNarrowLayout: boolean;
  139. /**
  140. * Whether or not speaker stats is disable.
  141. */
  142. _isSpeakerStatsDisabled?: boolean;
  143. /**
  144. * The array of toolbar buttons disabled through jwt features.
  145. */
  146. _jwtDisabledButons: string[];
  147. /**
  148. * Whether or not the overflow menu is displayed in a drawer drawer.
  149. */
  150. _overflowDrawer: boolean;
  151. /**
  152. * Whether or not the overflow menu is visible.
  153. */
  154. _overflowMenuVisible: boolean;
  155. /**
  156. * Whether or not the participants pane is open.
  157. */
  158. _participantsPaneOpen: boolean;
  159. /**
  160. * Whether or not the local participant's hand is raised.
  161. */
  162. _raisedHand: boolean;
  163. /**
  164. * Whether or not to display reactions in separate button.
  165. */
  166. _reactionsButtonEnabled: boolean;
  167. /**
  168. * Whether or not reactions feature is enabled.
  169. */
  170. _reactionsEnabled: boolean;
  171. /**
  172. * Whether or not the local participant is screenSharing.
  173. */
  174. _screenSharing: boolean;
  175. /**
  176. * Whether the toolbox should be shifted up or not.
  177. */
  178. _shiftUp: boolean;
  179. /**
  180. * Whether or not the tile view is enabled.
  181. */
  182. _tileViewEnabled: boolean;
  183. /**
  184. * The enabled buttons.
  185. */
  186. _toolbarButtons: Array<string>;
  187. /**
  188. * Flag showing whether toolbar is visible.
  189. */
  190. _visible: boolean;
  191. /**
  192. * An object containing the CSS classes.
  193. */
  194. classes: any;
  195. /**
  196. * Invoked to active other features of the app.
  197. */
  198. dispatch: IStore['dispatch'];
  199. /**
  200. * Explicitly passed array with the buttons which this Toolbox should display.
  201. */
  202. toolbarButtons: Array<string>;
  203. }
  204. const styles = () => {
  205. return {
  206. contextMenu: {
  207. position: 'relative' as const,
  208. right: 'auto',
  209. margin: 0,
  210. marginBottom: '8px',
  211. maxHeight: 'calc(100vh - 100px)',
  212. minWidth: '240px'
  213. },
  214. hangupMenu: {
  215. position: 'relative' as const,
  216. right: 'auto',
  217. display: 'flex',
  218. flexDirection: 'column' as const,
  219. rowGap: '8px',
  220. margin: 0,
  221. padding: '16px',
  222. marginBottom: '4px'
  223. }
  224. };
  225. };
  226. /**
  227. * Implements the conference toolbox on React/Web.
  228. *
  229. * @augments Component
  230. */
  231. class Toolbox extends Component<IProps> {
  232. _toolboxRef: RefObject<HTMLDivElement>;
  233. /**
  234. * Initializes a new {@code Toolbox} instance.
  235. *
  236. * @param {IProps} props - The read-only React {@code Component} props with
  237. * which the new instance is to be initialized.
  238. */
  239. constructor(props: IProps) {
  240. super(props);
  241. this._toolboxRef = React.createRef();
  242. // Bind event handlers so they are only bound once per instance.
  243. this._onMouseOut = this._onMouseOut.bind(this);
  244. this._onMouseOver = this._onMouseOver.bind(this);
  245. this._onSetHangupVisible = this._onSetHangupVisible.bind(this);
  246. this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
  247. this._onTabIn = this._onTabIn.bind(this);
  248. this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
  249. this._onShortcutToggleFullScreen = this._onShortcutToggleFullScreen.bind(this);
  250. this._onShortcutToggleParticipantsPane = this._onShortcutToggleParticipantsPane.bind(this);
  251. this._onShortcutToggleRaiseHand = this._onShortcutToggleRaiseHand.bind(this);
  252. this._onShortcutToggleScreenshare = this._onShortcutToggleScreenshare.bind(this);
  253. this._onShortcutToggleVideoQuality = this._onShortcutToggleVideoQuality.bind(this);
  254. this._onShortcutToggleTileView = this._onShortcutToggleTileView.bind(this);
  255. this._onShortcutSpeakerStats = this._onShortcutSpeakerStats.bind(this);
  256. this._onEscKey = this._onEscKey.bind(this);
  257. }
  258. /**
  259. * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
  260. *
  261. * @inheritdoc
  262. * @returns {void}
  263. */
  264. componentDidMount() {
  265. const { _toolbarButtons, dispatch, _reactionsEnabled, _gifsEnabled, _isSpeakerStatsDisabled } = this.props;
  266. const KEYBOARD_SHORTCUTS = [
  267. isToolbarButtonEnabled('videoquality', _toolbarButtons) && {
  268. character: 'A',
  269. exec: this._onShortcutToggleVideoQuality,
  270. helpDescription: 'toolbar.callQuality'
  271. },
  272. isToolbarButtonEnabled('chat', _toolbarButtons) && {
  273. character: 'C',
  274. exec: this._onShortcutToggleChat,
  275. helpDescription: 'keyboardShortcuts.toggleChat'
  276. },
  277. isToolbarButtonEnabled('desktop', _toolbarButtons) && {
  278. character: 'D',
  279. exec: this._onShortcutToggleScreenshare,
  280. helpDescription: 'keyboardShortcuts.toggleScreensharing'
  281. },
  282. isToolbarButtonEnabled('participants-pane', _toolbarButtons) && {
  283. character: 'P',
  284. exec: this._onShortcutToggleParticipantsPane,
  285. helpDescription: 'keyboardShortcuts.toggleParticipantsPane'
  286. },
  287. isToolbarButtonEnabled('raisehand', _toolbarButtons) && {
  288. character: 'R',
  289. exec: this._onShortcutToggleRaiseHand,
  290. helpDescription: 'keyboardShortcuts.raiseHand'
  291. },
  292. isToolbarButtonEnabled('fullscreen', _toolbarButtons) && {
  293. character: 'S',
  294. exec: this._onShortcutToggleFullScreen,
  295. helpDescription: 'keyboardShortcuts.fullScreen'
  296. },
  297. isToolbarButtonEnabled('tileview', _toolbarButtons) && {
  298. character: 'W',
  299. exec: this._onShortcutToggleTileView,
  300. helpDescription: 'toolbar.tileViewToggle'
  301. },
  302. !_isSpeakerStatsDisabled && isToolbarButtonEnabled('stats', _toolbarButtons) && {
  303. character: 'T',
  304. exec: this._onShortcutSpeakerStats,
  305. helpDescription: 'keyboardShortcuts.showSpeakerStats'
  306. }
  307. ];
  308. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  309. if (typeof shortcut === 'object') {
  310. dispatch(registerShortcut({
  311. character: shortcut.character,
  312. handler: shortcut.exec,
  313. helpDescription: shortcut.helpDescription
  314. }));
  315. }
  316. });
  317. if (_reactionsEnabled) {
  318. const REACTION_SHORTCUTS = Object.keys(REACTIONS).map(key => {
  319. const onShortcutSendReaction = () => {
  320. dispatch(addReactionToBuffer(key));
  321. sendAnalytics(createShortcutEvent(
  322. `reaction.${key}`
  323. ));
  324. };
  325. return {
  326. character: REACTIONS[key].shortcutChar,
  327. exec: onShortcutSendReaction,
  328. helpDescription: `toolbar.reaction${key.charAt(0).toUpperCase()}${key.slice(1)}`,
  329. altKey: true
  330. };
  331. });
  332. REACTION_SHORTCUTS.forEach(shortcut => {
  333. dispatch(registerShortcut({
  334. alt: shortcut.altKey,
  335. character: shortcut.character,
  336. handler: shortcut.exec,
  337. helpDescription: shortcut.helpDescription
  338. }));
  339. });
  340. if (_gifsEnabled) {
  341. const onGifShortcut = () => {
  342. batch(() => {
  343. dispatch(toggleReactionsMenuVisibility());
  344. dispatch(setGifMenuVisibility(true));
  345. });
  346. };
  347. dispatch(registerShortcut({
  348. character: 'G',
  349. handler: onGifShortcut,
  350. helpDescription: 'keyboardShortcuts.giphyMenu'
  351. }));
  352. }
  353. }
  354. }
  355. /**
  356. * Update the visibility of the {@code OverflowMenuButton}.
  357. *
  358. * @inheritdoc
  359. */
  360. componentDidUpdate(prevProps: IProps) {
  361. const { _dialog, _visible, dispatch } = this.props;
  362. if (prevProps._overflowMenuVisible
  363. && !prevProps._dialog
  364. && _dialog) {
  365. this._onSetOverflowVisible(false);
  366. dispatch(setToolbarHovered(false));
  367. }
  368. if (prevProps._hangupMenuVisible
  369. && prevProps._visible
  370. && !_visible) {
  371. this._onSetHangupVisible(false);
  372. dispatch(setToolbarHovered(false));
  373. }
  374. if (!_visible && prevProps._visible !== _visible) {
  375. if (document.activeElement instanceof HTMLElement
  376. && this._toolboxRef.current?.contains(document.activeElement)) {
  377. document.activeElement.blur();
  378. }
  379. }
  380. }
  381. /**
  382. * Removes keyboard shortcuts registered by this component.
  383. *
  384. * @inheritdoc
  385. * @returns {void}
  386. */
  387. componentWillUnmount() {
  388. const { dispatch } = this.props;
  389. [ 'A', 'C', 'D', 'P', 'R', 'S', 'W', 'T', 'G' ].forEach(letter =>
  390. dispatch(unregisterShortcut(letter)));
  391. if (this.props._reactionsEnabled) {
  392. Object.keys(REACTIONS).map(key => REACTIONS[key].shortcutChar)
  393. .forEach(letter =>
  394. dispatch(unregisterShortcut(letter, true)));
  395. }
  396. }
  397. /**
  398. * Implements React's {@link Component#render()}.
  399. *
  400. * @inheritdoc
  401. * @returns {ReactElement}
  402. */
  403. render() {
  404. if (this.props._disabled) {
  405. return null;
  406. }
  407. const { _chatOpen, _visible, _toolbarButtons } = this.props;
  408. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  409. _toolbarButtons.length ? '' : 'no-buttons'} ${_chatOpen ? 'shift-right' : ''}`;
  410. return (
  411. <div
  412. className = { clsx(rootClassNames, this.props._shiftUp && 'shift-up') }
  413. id = 'new-toolbox'>
  414. { this._renderToolboxContent() }
  415. </div>
  416. );
  417. }
  418. /**
  419. * Key handler for overflow/hangup menus.
  420. *
  421. * @param {KeyboardEvent} e - Esc key click to close the popup.
  422. * @returns {void}
  423. */
  424. _onEscKey(e?: React.KeyboardEvent) {
  425. const { dispatch, _hangupMenuVisible, _overflowMenuVisible } = this.props;
  426. if (e?.key === 'Escape') {
  427. e?.stopPropagation();
  428. _hangupMenuVisible && dispatch(setHangupMenuVisible(false));
  429. _overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
  430. }
  431. }
  432. /**
  433. * Returns the notify mode of the given toolbox button.
  434. *
  435. * @param {string} btnName - The toolbar button's name.
  436. * @returns {string|undefined} - The button's notify mode.
  437. */
  438. _getButtonNotifyMode(btnName: string) {
  439. const notify = this.props._buttonsWithNotifyClick?.find(
  440. btn =>
  441. (typeof btn === 'string' && btn === btnName)
  442. || (typeof btn === 'object' && btn.key === btnName)
  443. );
  444. if (notify) {
  445. return typeof notify === 'string' || notify.preventExecution
  446. ? NOTIFY_CLICK_MODE.PREVENT_AND_NOTIFY
  447. : NOTIFY_CLICK_MODE.ONLY_NOTIFY;
  448. }
  449. }
  450. /**
  451. * Sets the notify click mode for the buttons.
  452. *
  453. * @param {Object} buttons - The list of toolbar buttons.
  454. * @returns {void}
  455. */
  456. _setButtonsNotifyClickMode(buttons: Object) {
  457. if (typeof APP === 'undefined' || !this.props._buttonsWithNotifyClick?.length) {
  458. return;
  459. }
  460. Object.values(buttons).forEach((button: any) => {
  461. if (typeof button === 'object') {
  462. button.notifyMode = this._getButtonNotifyMode(button.key);
  463. }
  464. });
  465. }
  466. /**
  467. * Returns all buttons that need to be rendered.
  468. *
  469. * @param {Object} state - The redux state.
  470. * @returns {Object} The visible buttons arrays .
  471. */
  472. _getVisibleButtons() {
  473. const {
  474. _clientWidth,
  475. _toolbarButtons,
  476. _jwtDisabledButons,
  477. _customToolbarButtons
  478. } = this.props;
  479. const buttons = getAllToolboxButtons(_customToolbarButtons);
  480. this._setButtonsNotifyClickMode(buttons);
  481. const isHangupVisible = isToolbarButtonEnabled('hangup', _toolbarButtons);
  482. let { order } = THRESHOLDS.find(({ width }) => _clientWidth > width)
  483. || THRESHOLDS[THRESHOLDS.length - 1];
  484. const keys = Object.keys(buttons);
  485. const filtered = [
  486. ...order.map(key => buttons[key as keyof typeof buttons]),
  487. ...Object.values(buttons).filter((button, index) => !order.includes(keys[index]))
  488. ].filter(({ key, alias = NOT_APPLICABLE }) =>
  489. !_jwtDisabledButons.includes(key)
  490. && (isToolbarButtonEnabled(key, _toolbarButtons) || isToolbarButtonEnabled(alias, _toolbarButtons))
  491. );
  492. const filteredKeys = filtered.map(button => button.key);
  493. order = order.filter(key => filteredKeys.includes(buttons[key as keyof typeof buttons].key));
  494. let sliceIndex = order.length + 2;
  495. if (isHangupVisible) {
  496. sliceIndex -= 1;
  497. }
  498. // This implies that the overflow button will be displayed, so save some space for it.
  499. if (sliceIndex < filtered.length) {
  500. sliceIndex -= 1;
  501. }
  502. return {
  503. mainMenuButtons: filtered.slice(0, sliceIndex),
  504. overflowMenuButtons: filtered.slice(sliceIndex)
  505. };
  506. }
  507. /**
  508. * Dispatches an action signaling the toolbar is not being hovered.
  509. *
  510. * @private
  511. * @returns {void}
  512. */
  513. _onMouseOut() {
  514. const { _overflowMenuVisible, dispatch } = this.props;
  515. !_overflowMenuVisible && dispatch(setToolbarHovered(false));
  516. }
  517. /**
  518. * Dispatches an action signaling the toolbar is being hovered.
  519. *
  520. * @private
  521. * @returns {void}
  522. */
  523. _onMouseOver() {
  524. this.props.dispatch(setToolbarHovered(true));
  525. }
  526. /**
  527. * Sets the visibility of the hangup menu.
  528. *
  529. * @param {boolean} visible - Whether or not the hangup menu should be
  530. * displayed.
  531. * @private
  532. * @returns {void}
  533. */
  534. _onSetHangupVisible(visible: boolean) {
  535. this.props.dispatch(setHangupMenuVisible(visible));
  536. this.props.dispatch(setToolbarHovered(visible));
  537. }
  538. /**
  539. * Sets the visibility of the overflow menu.
  540. *
  541. * @param {boolean} visible - Whether or not the overflow menu should be
  542. * displayed.
  543. * @private
  544. * @returns {void}
  545. */
  546. _onSetOverflowVisible(visible: boolean) {
  547. this.props.dispatch(setOverflowMenuVisible(visible));
  548. this.props.dispatch(setToolbarHovered(visible));
  549. }
  550. /**
  551. * Creates an analytics keyboard shortcut event and dispatches an action for
  552. * toggling the display of chat.
  553. *
  554. * @private
  555. * @returns {void}
  556. */
  557. _onShortcutToggleChat() {
  558. sendAnalytics(createShortcutEvent(
  559. 'toggle.chat',
  560. ACTION_SHORTCUT_TRIGGERED,
  561. {
  562. enable: !this.props._chatOpen
  563. }));
  564. // Checks if there was any text selected by the user.
  565. // Used for when we press simultaneously keys for copying
  566. // text messages from the chat board
  567. if (window.getSelection()?.toString() !== '') {
  568. return false;
  569. }
  570. this.props.dispatch(toggleChat());
  571. }
  572. /**
  573. * Creates an analytics keyboard shortcut event and dispatches an action for
  574. * toggling the display of the participants pane.
  575. *
  576. * @private
  577. * @returns {void}
  578. */
  579. _onShortcutToggleParticipantsPane() {
  580. const { dispatch, _participantsPaneOpen } = this.props;
  581. sendAnalytics(createShortcutEvent(
  582. 'toggle.participants-pane',
  583. ACTION_SHORTCUT_TRIGGERED,
  584. {
  585. enable: !this.props._participantsPaneOpen
  586. }));
  587. if (_participantsPaneOpen) {
  588. dispatch(closeParticipantsPane());
  589. } else {
  590. dispatch(openParticipantsPane());
  591. }
  592. }
  593. /**
  594. * Creates an analytics keyboard shortcut event and dispatches an action for
  595. * toggling the display of Video Quality.
  596. *
  597. * @private
  598. * @returns {void}
  599. */
  600. _onShortcutToggleVideoQuality() {
  601. sendAnalytics(createShortcutEvent('video.quality'));
  602. this.props.dispatch(toggleDialog(VideoQualityDialog));
  603. }
  604. /**
  605. * Dispatches an action for toggling the tile view.
  606. *
  607. * @private
  608. * @returns {void}
  609. */
  610. _onShortcutToggleTileView() {
  611. sendAnalytics(createShortcutEvent(
  612. 'toggle.tileview',
  613. ACTION_SHORTCUT_TRIGGERED,
  614. {
  615. enable: !this.props._tileViewEnabled
  616. }));
  617. this.props.dispatch(toggleTileView());
  618. }
  619. /**
  620. * Creates an analytics keyboard shortcut event and dispatches an action for
  621. * toggling full screen mode.
  622. *
  623. * @private
  624. * @returns {void}
  625. */
  626. _onShortcutToggleFullScreen() {
  627. const { dispatch, _fullScreen } = this.props;
  628. sendAnalytics(createShortcutEvent(
  629. 'toggle.fullscreen',
  630. ACTION_SHORTCUT_TRIGGERED,
  631. {
  632. enable: !_fullScreen
  633. }));
  634. dispatch(setFullScreen(!_fullScreen));
  635. }
  636. /**
  637. * Creates an analytics keyboard shortcut event and dispatches an action for
  638. * toggling raise hand.
  639. *
  640. * @private
  641. * @returns {void}
  642. */
  643. _onShortcutToggleRaiseHand() {
  644. const { dispatch, _raisedHand } = this.props;
  645. sendAnalytics(createShortcutEvent(
  646. 'toggle.raise.hand',
  647. ACTION_SHORTCUT_TRIGGERED,
  648. { enable: !_raisedHand }));
  649. dispatch(raiseHand(!_raisedHand));
  650. }
  651. /**
  652. * Creates an analytics keyboard shortcut event and dispatches an action for
  653. * toggling screensharing.
  654. *
  655. * @private
  656. * @returns {void}
  657. */
  658. _onShortcutToggleScreenshare() {
  659. const {
  660. _desktopSharingButtonDisabled,
  661. _desktopSharingEnabled,
  662. _screenSharing,
  663. dispatch
  664. } = this.props;
  665. // Ignore the shortcut if the button is disabled.
  666. if (_desktopSharingButtonDisabled) {
  667. return;
  668. }
  669. sendAnalytics(createShortcutEvent(
  670. 'toggle.screen.sharing',
  671. ACTION_SHORTCUT_TRIGGERED,
  672. {
  673. enable: !_screenSharing
  674. }));
  675. if (_desktopSharingEnabled && !_desktopSharingButtonDisabled) {
  676. dispatch(startScreenShareFlow(!_screenSharing));
  677. }
  678. }
  679. /**
  680. * Creates an analytics keyboard shortcut event and dispatches an action for
  681. * toggling speaker stats.
  682. *
  683. * @private
  684. * @returns {void}
  685. */
  686. _onShortcutSpeakerStats() {
  687. const { dispatch } = this.props;
  688. sendAnalytics(createShortcutEvent(
  689. 'speaker.stats'
  690. ));
  691. dispatch(toggleDialog(SpeakerStats, {
  692. conference: APP.conference
  693. }));
  694. }
  695. /**
  696. * Toggle the toolbar visibility when tabbing into it.
  697. *
  698. * @returns {void}
  699. */
  700. _onTabIn() {
  701. if (!this.props._visible) {
  702. this.props.dispatch(showToolbox());
  703. }
  704. }
  705. /**
  706. * Renders the toolbox content.
  707. *
  708. * @returns {ReactElement}
  709. */
  710. _renderToolboxContent() {
  711. const {
  712. _endConferenceSupported,
  713. _hangupMenuVisible,
  714. _isMobile,
  715. _isNarrowLayout,
  716. _overflowDrawer,
  717. _overflowMenuVisible,
  718. _reactionsEnabled,
  719. _reactionsButtonEnabled,
  720. _toolbarButtons,
  721. classes,
  722. t
  723. } = this.props;
  724. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  725. const containerClassName = `toolbox-content${_isMobile || _isNarrowLayout ? ' toolbox-content-mobile' : ''}`;
  726. const { mainMenuButtons, overflowMenuButtons } = this._getVisibleButtons();
  727. const raiseHandInOverflowMenu = overflowMenuButtons.some(({ key }) => key === 'raisehand');
  728. const showReactionsInOverflowMenu
  729. = (_reactionsEnabled && !_reactionsButtonEnabled
  730. && (raiseHandInOverflowMenu || _isNarrowLayout || _isMobile))
  731. || overflowMenuButtons.some(({ key }) => key === 'reactions');
  732. const showRaiseHandInReactionsMenu = showReactionsInOverflowMenu && raiseHandInOverflowMenu;
  733. return (
  734. <div className = { containerClassName }>
  735. <div
  736. className = 'toolbox-content-wrapper'
  737. onFocus = { this._onTabIn }
  738. { ...(_isMobile ? {} : {
  739. onMouseOut: this._onMouseOut,
  740. onMouseOver: this._onMouseOver
  741. }) }>
  742. <div
  743. className = 'toolbox-content-items'
  744. ref = { this._toolboxRef }>
  745. {mainMenuButtons.map(({ Content, key, ...rest }) => Content !== Separator && (
  746. <Content
  747. { ...rest }
  748. buttonKey = { key }
  749. key = { key } />))}
  750. {Boolean(overflowMenuButtons.length) && (
  751. <OverflowMenuButton
  752. ariaControls = 'overflow-menu'
  753. buttons = { overflowMenuButtons.reduce<Array<IToolboxButton[]>>((acc, val) => {
  754. if (val.key === 'reactions' && showReactionsInOverflowMenu) {
  755. return acc;
  756. }
  757. if (val.key === 'raisehand' && showRaiseHandInReactionsMenu) {
  758. return acc;
  759. }
  760. if (acc.length) {
  761. const prev = acc[acc.length - 1];
  762. const group = prev[prev.length - 1].group;
  763. if (group === val.group) {
  764. prev.push(val);
  765. } else {
  766. acc.push([ val ]);
  767. }
  768. } else {
  769. acc.push([ val ]);
  770. }
  771. return acc;
  772. }, []) }
  773. isOpen = { _overflowMenuVisible }
  774. key = 'overflow-menu'
  775. onToolboxEscKey = { this._onEscKey }
  776. onVisibilityChange = { this._onSetOverflowVisible }
  777. showRaiseHandInReactionsMenu = { showRaiseHandInReactionsMenu }
  778. showReactionsMenu = { showReactionsInOverflowMenu } />
  779. )}
  780. { isToolbarButtonEnabled('hangup', _toolbarButtons) && (
  781. _endConferenceSupported
  782. ? <HangupMenuButton
  783. ariaControls = 'hangup-menu'
  784. isOpen = { _hangupMenuVisible }
  785. key = 'hangup-menu'
  786. notifyMode = { this._getButtonNotifyMode('hangup-menu') }
  787. onVisibilityChange = { this._onSetHangupVisible }>
  788. <ContextMenu
  789. accessibilityLabel = { t(toolbarAccLabel) }
  790. className = { classes.hangupMenu }
  791. hidden = { false }
  792. inDrawer = { _overflowDrawer }
  793. onKeyDown = { this._onEscKey }>
  794. <EndConferenceButton
  795. buttonKey = 'end-meeting'
  796. notifyMode = { this._getButtonNotifyMode('end-meeting') } />
  797. <LeaveConferenceButton
  798. buttonKey = 'hangup'
  799. notifyMode = { this._getButtonNotifyMode('hangup') } />
  800. </ContextMenu>
  801. </HangupMenuButton>
  802. : <HangupButton
  803. buttonKey = 'hangup'
  804. customClass = 'hangup-button'
  805. key = 'hangup-button'
  806. notifyMode = { this._getButtonNotifyMode('hangup') }
  807. visible = { isToolbarButtonEnabled('hangup', _toolbarButtons) } />
  808. )}
  809. </div>
  810. </div>
  811. </div>
  812. );
  813. }
  814. }
  815. /**
  816. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  817. * props.
  818. *
  819. * @param {Object} state - The redux store/state.
  820. * @param {Object} ownProps - The props explicitly passed.
  821. * @private
  822. * @returns {{}}
  823. */
  824. function _mapStateToProps(state: IReduxState, ownProps: any) {
  825. const { conference } = state['features/base/conference'];
  826. const { isNarrowLayout } = state['features/base/responsive-ui'];
  827. const endConferenceSupported = conference?.isEndConferenceSupported() && isLocalParticipantModerator(state);
  828. const {
  829. customToolbarButtons,
  830. iAmRecorder,
  831. iAmSipGateway
  832. } = state['features/base/config'];
  833. const {
  834. fullScreen,
  835. hangupMenuVisible,
  836. overflowMenuVisible,
  837. overflowDrawer
  838. } = state['features/toolbox'];
  839. const localParticipant = getLocalParticipant(state);
  840. const { clientWidth } = state['features/base/responsive-ui'];
  841. let toolbarButtons = ownProps.toolbarButtons || getToolbarButtons(state);
  842. const _reactionsEnabled = isReactionsEnabled(state);
  843. if (iAmVisitor(state)) {
  844. toolbarButtons = VISITORS_MODE_BUTTONS.filter(e => toolbarButtons.indexOf(e) > -1);
  845. }
  846. return {
  847. _buttonsWithNotifyClick: getButtonsWithNotifyClick(state),
  848. _chatOpen: state['features/chat'].isOpen,
  849. _clientWidth: clientWidth,
  850. _customToolbarButtons: customToolbarButtons,
  851. _desktopSharingEnabled: JitsiMeetJS.isDesktopSharingEnabled(),
  852. _desktopSharingButtonDisabled: isDesktopShareButtonDisabled(state),
  853. _dialog: Boolean(state['features/base/dialog'].component),
  854. _disabled: Boolean(iAmRecorder || iAmSipGateway),
  855. _endConferenceSupported: Boolean(endConferenceSupported),
  856. _fullScreen: fullScreen,
  857. _gifsEnabled: isGifEnabled(state),
  858. _isMobile: isMobileBrowser(),
  859. _isSpeakerStatsDisabled: isSpeakerStatsDisabled(state),
  860. _jwtDisabledButons: getJwtDisabledButtons(state),
  861. _hangupMenuVisible: hangupMenuVisible,
  862. _isNarrowLayout: isNarrowLayout,
  863. _overflowMenuVisible: overflowMenuVisible,
  864. _overflowDrawer: overflowDrawer,
  865. _participantsPaneOpen: getParticipantsPaneOpen(state),
  866. _raisedHand: hasRaisedHand(localParticipant),
  867. _reactionsButtonEnabled: isReactionsButtonEnabled(state),
  868. _reactionsEnabled,
  869. _screenSharing: isScreenVideoShared(state),
  870. _shiftUp: state['features/toolbox'].shiftUp,
  871. _tileViewEnabled: shouldDisplayTileView(state),
  872. _toolbarButtons: toolbarButtons,
  873. _visible: isToolboxVisible(state)
  874. };
  875. }
  876. export default translate(connect(_mapStateToProps)(withStyles(styles)(Toolbox)));