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.js 36KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. // @flow
  2. import React, { Component } from 'react';
  3. import keyboardShortcut from '../../../../../modules/keyboardshortcut/keyboardshortcut';
  4. import {
  5. ACTION_SHORTCUT_TRIGGERED,
  6. createShortcutEvent,
  7. createToolbarEvent,
  8. sendAnalytics
  9. } from '../../../analytics';
  10. import { getToolbarButtons } from '../../../base/config';
  11. import { isToolbarButtonEnabled } from '../../../base/config/functions.web';
  12. import { openDialog, toggleDialog } from '../../../base/dialog';
  13. import { isMobileBrowser } from '../../../base/environment/utils';
  14. import { translate } from '../../../base/i18n';
  15. import JitsiMeetJS from '../../../base/lib-jitsi-meet';
  16. import {
  17. getLocalParticipant,
  18. haveParticipantWithScreenSharingFeature,
  19. raiseHand
  20. } from '../../../base/participants';
  21. import { connect } from '../../../base/redux';
  22. import { getLocalVideoTrack } from '../../../base/tracks';
  23. import { toggleChat } from '../../../chat';
  24. import { ChatButton } from '../../../chat/components';
  25. import { EmbedMeetingButton } from '../../../embed-meeting';
  26. import { SharedDocumentButton } from '../../../etherpad';
  27. import { FeedbackButton } from '../../../feedback';
  28. import { isVpaasMeeting } from '../../../jaas/functions';
  29. import { KeyboardShortcutsButton } from '../../../keyboard-shortcuts';
  30. import { LocalRecordingButton } from '../../../local-recording';
  31. import {
  32. close as closeParticipantsPane,
  33. open as openParticipantsPane
  34. } from '../../../participants-pane/actions';
  35. import ParticipantsPaneButton from '../../../participants-pane/components/ParticipantsPaneButton';
  36. import { getParticipantsPaneOpen } from '../../../participants-pane/functions';
  37. import { addReactionToBuffer } from '../../../reactions/actions.any';
  38. import { ReactionsMenuButton } from '../../../reactions/components';
  39. import { REACTIONS } from '../../../reactions/constants';
  40. import {
  41. LiveStreamButton,
  42. RecordButton
  43. } from '../../../recording';
  44. import {
  45. isScreenAudioSupported,
  46. isScreenVideoShared,
  47. ShareAudioButton,
  48. startScreenShareFlow
  49. } from '../../../screen-share/';
  50. import SecurityDialogButton from '../../../security/components/security-dialog/SecurityDialogButton';
  51. import { SettingsButton } from '../../../settings';
  52. import { SharedVideoButton } from '../../../shared-video/components';
  53. import { SpeakerStatsButton } from '../../../speaker-stats';
  54. import {
  55. ClosedCaptionButton
  56. } from '../../../subtitles';
  57. import {
  58. TileViewButton,
  59. shouldDisplayTileView,
  60. toggleTileView
  61. } from '../../../video-layout';
  62. import { VideoQualityDialog, VideoQualityButton } from '../../../video-quality/components';
  63. import { VideoBackgroundButton } from '../../../virtual-background';
  64. import { toggleBackgroundEffect } from '../../../virtual-background/actions';
  65. import { VIRTUAL_BACKGROUND_TYPE } from '../../../virtual-background/constants';
  66. import { checkBlurSupport } from '../../../virtual-background/functions';
  67. import {
  68. setFullScreen,
  69. setOverflowMenuVisible,
  70. setToolbarHovered,
  71. showToolbox
  72. } from '../../actions';
  73. import { THRESHOLDS } from '../../constants';
  74. import { isToolboxVisible } from '../../functions';
  75. import DownloadButton from '../DownloadButton';
  76. import HangupButton from '../HangupButton';
  77. import HelpButton from '../HelpButton';
  78. import MuteEveryoneButton from '../MuteEveryoneButton';
  79. import MuteEveryonesVideoButton from '../MuteEveryonesVideoButton';
  80. import AudioSettingsButton from './AudioSettingsButton';
  81. import FullscreenButton from './FullscreenButton';
  82. import OverflowMenuButton from './OverflowMenuButton';
  83. import ProfileButton from './ProfileButton';
  84. import Separator from './Separator';
  85. import ShareDesktopButton from './ShareDesktopButton';
  86. import VideoSettingsButton from './VideoSettingsButton';
  87. /**
  88. * The type of the React {@code Component} props of {@link Toolbox}.
  89. */
  90. type Props = {
  91. /**
  92. * String showing if the virtual background type is desktop-share.
  93. */
  94. _backgroundType: String,
  95. /**
  96. * Whether or not the chat feature is currently displayed.
  97. */
  98. _chatOpen: boolean,
  99. /**
  100. * The width of the client.
  101. */
  102. _clientWidth: number,
  103. /**
  104. * The {@code JitsiConference} for the current conference.
  105. */
  106. _conference: Object,
  107. /**
  108. * The tooltip key to use when screensharing is disabled. Or undefined
  109. * if non to be shown and the button to be hidden.
  110. */
  111. _desktopSharingDisabledTooltipKey: boolean,
  112. /**
  113. * Whether or not screensharing is initialized.
  114. */
  115. _desktopSharingEnabled: boolean,
  116. /**
  117. * Whether or not a dialog is displayed.
  118. */
  119. _dialog: boolean,
  120. /**
  121. * Whether or not call feedback can be sent.
  122. */
  123. _feedbackConfigured: boolean,
  124. /**
  125. * Whether or not the app is currently in full screen.
  126. */
  127. _fullScreen: boolean,
  128. /**
  129. * Whether or not the app is running in mobile browser.
  130. */
  131. _isMobile: boolean,
  132. /**
  133. * Whether or not the profile is disabled.
  134. */
  135. _isProfileDisabled: boolean,
  136. /**
  137. * Whether or not the tile view is enabled.
  138. */
  139. _tileViewEnabled: boolean,
  140. /**
  141. * Whether or not the current meeting belongs to a JaaS user.
  142. */
  143. _isVpaasMeeting: boolean,
  144. /**
  145. * The ID of the local participant.
  146. */
  147. _localParticipantID: String,
  148. /**
  149. * The JitsiLocalTrack to display.
  150. */
  151. _localVideo: Object,
  152. /**
  153. * Whether or not the overflow menu is visible.
  154. */
  155. _overflowMenuVisible: boolean,
  156. /**
  157. * Whether or not the participants pane is open.
  158. */
  159. _participantsPaneOpen: boolean,
  160. /**
  161. * Whether or not the local participant's hand is raised.
  162. */
  163. _raisedHand: boolean,
  164. /**
  165. * Whether or not the local participant is screenSharing.
  166. */
  167. _screenSharing: boolean,
  168. /**
  169. * Whether or not the local participant is sharing a YouTube video.
  170. */
  171. _sharingVideo: boolean,
  172. /**
  173. * The enabled buttons.
  174. */
  175. _toolbarButtons: Array<string>,
  176. /**
  177. * Flag showing whether toolbar is visible.
  178. */
  179. _visible: boolean,
  180. /**
  181. * Array with the buttons which this Toolbox should display.
  182. */
  183. _visibleButtons: Array<string>,
  184. /**
  185. * Returns the selected virtual source object.
  186. */
  187. _virtualSource: Object,
  188. /**
  189. * Invoked to active other features of the app.
  190. */
  191. dispatch: Function,
  192. /**
  193. * Invoked to obtain translated strings.
  194. */
  195. t: Function
  196. };
  197. declare var APP: Object;
  198. /**
  199. * Implements the conference toolbox on React/Web.
  200. *
  201. * @extends Component
  202. */
  203. class Toolbox extends Component<Props> {
  204. /**
  205. * Initializes a new {@code Toolbox} instance.
  206. *
  207. * @param {Props} props - The read-only React {@code Component} props with
  208. * which the new instance is to be initialized.
  209. */
  210. constructor(props: Props) {
  211. super(props);
  212. // Bind event handlers so they are only bound once per instance.
  213. this._onMouseOut = this._onMouseOut.bind(this);
  214. this._onMouseOver = this._onMouseOver.bind(this);
  215. this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
  216. this._onTabIn = this._onTabIn.bind(this);
  217. this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
  218. this._onShortcutToggleFullScreen = this._onShortcutToggleFullScreen.bind(this);
  219. this._onShortcutToggleParticipantsPane = this._onShortcutToggleParticipantsPane.bind(this);
  220. this._onShortcutToggleRaiseHand = this._onShortcutToggleRaiseHand.bind(this);
  221. this._onShortcutToggleScreenshare = this._onShortcutToggleScreenshare.bind(this);
  222. this._onShortcutToggleVideoQuality = this._onShortcutToggleVideoQuality.bind(this);
  223. this._onToolbarToggleParticipantsPane = this._onToolbarToggleParticipantsPane.bind(this);
  224. this._onToolbarOpenVideoQuality = this._onToolbarOpenVideoQuality.bind(this);
  225. this._onToolbarToggleChat = this._onToolbarToggleChat.bind(this);
  226. this._onToolbarToggleFullScreen = this._onToolbarToggleFullScreen.bind(this);
  227. this._onToolbarToggleScreenshare = this._onToolbarToggleScreenshare.bind(this);
  228. this._onShortcutToggleTileView = this._onShortcutToggleTileView.bind(this);
  229. this._onEscKey = this._onEscKey.bind(this);
  230. }
  231. /**
  232. * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
  233. *
  234. * @inheritdoc
  235. * @returns {void}
  236. */
  237. componentDidMount() {
  238. const { _toolbarButtons, t, dispatch } = this.props;
  239. const KEYBOARD_SHORTCUTS = [
  240. isToolbarButtonEnabled('videoquality', _toolbarButtons) && {
  241. character: 'A',
  242. exec: this._onShortcutToggleVideoQuality,
  243. helpDescription: 'toolbar.callQuality'
  244. },
  245. isToolbarButtonEnabled('chat', _toolbarButtons) && {
  246. character: 'C',
  247. exec: this._onShortcutToggleChat,
  248. helpDescription: 'keyboardShortcuts.toggleChat'
  249. },
  250. isToolbarButtonEnabled('desktop', _toolbarButtons) && {
  251. character: 'D',
  252. exec: this._onShortcutToggleScreenshare,
  253. helpDescription: 'keyboardShortcuts.toggleScreensharing'
  254. },
  255. isToolbarButtonEnabled('participants-pane', _toolbarButtons) && {
  256. character: 'P',
  257. exec: this._onShortcutToggleParticipantsPane,
  258. helpDescription: 'keyboardShortcuts.toggleParticipantsPane'
  259. },
  260. isToolbarButtonEnabled('raisehand', _toolbarButtons) && {
  261. character: 'R',
  262. exec: this._onShortcutToggleRaiseHand,
  263. helpDescription: 'keyboardShortcuts.raiseHand'
  264. },
  265. isToolbarButtonEnabled('fullscreen', _toolbarButtons) && {
  266. character: 'S',
  267. exec: this._onShortcutToggleFullScreen,
  268. helpDescription: 'keyboardShortcuts.fullScreen'
  269. },
  270. isToolbarButtonEnabled('tileview', _toolbarButtons) && {
  271. character: 'W',
  272. exec: this._onShortcutToggleTileView,
  273. helpDescription: 'toolbar.tileViewToggle'
  274. }
  275. ];
  276. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  277. if (typeof shortcut === 'object') {
  278. APP.keyboardshortcut.registerShortcut(
  279. shortcut.character,
  280. null,
  281. shortcut.exec,
  282. shortcut.helpDescription);
  283. }
  284. });
  285. const REACTION_SHORTCUTS = Object.keys(REACTIONS).map(key => {
  286. const onShortcutSendReaction = () => {
  287. dispatch(addReactionToBuffer(key));
  288. sendAnalytics(createShortcutEvent(
  289. `reaction.${key}`
  290. ));
  291. };
  292. return {
  293. character: REACTIONS[key].shortcutChar,
  294. exec: onShortcutSendReaction,
  295. helpDescription: t(`toolbar.reaction${key.charAt(0).toUpperCase()}${key.slice(1)}`),
  296. altKey: true
  297. };
  298. });
  299. REACTION_SHORTCUTS.forEach(shortcut => {
  300. APP.keyboardshortcut.registerShortcut(
  301. shortcut.character,
  302. null,
  303. shortcut.exec,
  304. shortcut.helpDescription,
  305. shortcut.altKey);
  306. });
  307. }
  308. /**
  309. * Update the visibility of the {@code OverflowMenuButton}.
  310. *
  311. * @inheritdoc
  312. */
  313. componentDidUpdate(prevProps) {
  314. // Ensure the dialog is closed when the toolbox becomes hidden.
  315. if (prevProps._overflowMenuVisible && !this.props._visible) {
  316. this._onSetOverflowVisible(false);
  317. }
  318. if (prevProps._overflowMenuVisible
  319. && !prevProps._dialog
  320. && this.props._dialog) {
  321. this._onSetOverflowVisible(false);
  322. this.props.dispatch(setToolbarHovered(false));
  323. }
  324. }
  325. /**
  326. * Removes keyboard shortcuts registered by this component.
  327. *
  328. * @inheritdoc
  329. * @returns {void}
  330. */
  331. componentWillUnmount() {
  332. [ 'A', 'C', 'D', 'R', 'S' ].forEach(letter =>
  333. APP.keyboardshortcut.unregisterShortcut(letter));
  334. Object.keys(REACTIONS).map(key => REACTIONS[key].shortcutChar)
  335. .forEach(letter =>
  336. APP.keyboardshortcut.unregisterShortcut(letter, true));
  337. }
  338. /**
  339. * Implements React's {@link Component#render()}.
  340. *
  341. * @inheritdoc
  342. * @returns {ReactElement}
  343. */
  344. render() {
  345. const { _chatOpen, _visible, _visibleButtons } = this.props;
  346. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  347. _visibleButtons.length ? '' : 'no-buttons'} ${_chatOpen ? 'shift-right' : ''}`;
  348. return (
  349. <div
  350. className = { rootClassNames }
  351. id = 'new-toolbox'>
  352. { this._renderToolboxContent() }
  353. </div>
  354. );
  355. }
  356. _onEscKey: (KeyboardEvent) => void;
  357. /**
  358. * Key handler for overflow menu.
  359. *
  360. * @param {KeyboardEvent} e - Esc key click to close the popup.
  361. * @returns {void}
  362. */
  363. _onEscKey(e) {
  364. if (e.key === 'Escape') {
  365. e.stopPropagation();
  366. this._closeOverflowMenuIfOpen();
  367. }
  368. }
  369. /**
  370. * Closes the overflow menu if opened.
  371. *
  372. * @private
  373. * @returns {void}
  374. */
  375. _closeOverflowMenuIfOpen() {
  376. const { dispatch, _overflowMenuVisible } = this.props;
  377. _overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
  378. }
  379. /**
  380. * Dispatches an action to open the video quality dialog.
  381. *
  382. * @private
  383. * @returns {void}
  384. */
  385. _doOpenVideoQuality() {
  386. this.props.dispatch(openDialog(VideoQualityDialog));
  387. }
  388. /**
  389. * Dispatches an action to toggle the display of chat.
  390. *
  391. * @private
  392. * @returns {void}
  393. */
  394. _doToggleChat() {
  395. this.props.dispatch(toggleChat());
  396. }
  397. /**
  398. * Dispatches an action to toggle screensharing.
  399. *
  400. * @private
  401. * @returns {void}
  402. */
  403. _doToggleFullScreen() {
  404. const fullScreen = !this.props._fullScreen;
  405. this.props.dispatch(setFullScreen(fullScreen));
  406. }
  407. /**
  408. * Dispatches an action to toggle the local participant's raised hand state.
  409. *
  410. * @private
  411. * @returns {void}
  412. */
  413. _doToggleRaiseHand() {
  414. const { _localParticipantID, _raisedHand } = this.props;
  415. const newRaisedStatus = !_raisedHand;
  416. this.props.dispatch(raiseHand(newRaisedStatus));
  417. APP.API.notifyRaiseHandUpdated(_localParticipantID, newRaisedStatus);
  418. }
  419. /**
  420. * Dispatches an action to toggle screensharing.
  421. *
  422. * @private
  423. * @param {boolean} enabled - The state to toggle screen sharing to.
  424. * @param {boolean} audioOnly - Only share system audio.
  425. * @returns {void}
  426. */
  427. _doToggleScreenshare() {
  428. const {
  429. _backgroundType,
  430. _desktopSharingEnabled,
  431. _localVideo,
  432. _virtualSource,
  433. dispatch
  434. } = this.props;
  435. if (_backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
  436. const noneOptions = {
  437. enabled: false,
  438. backgroundType: VIRTUAL_BACKGROUND_TYPE.NONE,
  439. selectedThumbnail: VIRTUAL_BACKGROUND_TYPE.NONE,
  440. backgroundEffectEnabled: false
  441. };
  442. _virtualSource.dispose();
  443. dispatch(toggleBackgroundEffect(noneOptions, _localVideo));
  444. return;
  445. }
  446. if (_desktopSharingEnabled) {
  447. dispatch(startScreenShareFlow());
  448. }
  449. }
  450. /**
  451. * Dispatches an action to toggle the video quality dialog.
  452. *
  453. * @private
  454. * @returns {void}
  455. */
  456. _doToggleVideoQuality() {
  457. this.props.dispatch(toggleDialog(VideoQualityDialog));
  458. }
  459. /**
  460. * Dispaches an action to toggle tile view.
  461. *
  462. * @private
  463. * @returns {void}
  464. */
  465. _doToggleTileView() {
  466. this.props.dispatch(toggleTileView());
  467. }
  468. /**
  469. * Returns all buttons that could be rendered.
  470. *
  471. * @param {Object} state - The redux state.
  472. * @returns {Object} The button maps mainMenuButtons and overflowMenuButtons.
  473. */
  474. _getAllButtons() {
  475. const {
  476. _feedbackConfigured,
  477. _isMobile,
  478. _screenSharing
  479. } = this.props;
  480. const microphone = {
  481. key: 'microphone',
  482. Content: AudioSettingsButton,
  483. group: 0
  484. };
  485. const camera = {
  486. key: 'camera',
  487. Content: VideoSettingsButton,
  488. group: 0
  489. };
  490. const profile = this._isProfileVisible() && {
  491. key: 'profile',
  492. Content: ProfileButton,
  493. group: 1
  494. };
  495. const chat = {
  496. key: 'chat',
  497. Content: ChatButton,
  498. handleClick: this._onToolbarToggleChat,
  499. group: 2
  500. };
  501. const desktop = this._showDesktopSharingButton() && {
  502. key: 'desktop',
  503. Content: ShareDesktopButton,
  504. handleClick: this._onToolbarToggleScreenshare,
  505. group: 2
  506. };
  507. const raisehand = {
  508. key: 'raisehand',
  509. Content: ReactionsMenuButton,
  510. group: 2
  511. };
  512. const participants = {
  513. key: 'participants-pane',
  514. Content: ParticipantsPaneButton,
  515. handleClick: this._onToolbarToggleParticipantsPane,
  516. group: 2
  517. };
  518. const tileview = {
  519. key: 'tileview',
  520. Content: TileViewButton,
  521. group: 2
  522. };
  523. const videoQuality = {
  524. key: 'videoquality',
  525. Content: VideoQualityButton,
  526. handleClick: this._onToolbarOpenVideoQuality,
  527. group: 2
  528. };
  529. const fullscreen = !_isMobile && {
  530. key: 'fullscreen',
  531. Content: FullscreenButton,
  532. handleClick: this._onToolbarToggleFullScreen,
  533. group: 2
  534. };
  535. const security = {
  536. key: 'security',
  537. Content: SecurityDialogButton,
  538. group: 2
  539. };
  540. const info = {
  541. key: 'info',
  542. Content: SecurityDialogButton,
  543. group: 2
  544. };
  545. const cc = {
  546. key: 'closedcaptions',
  547. Content: ClosedCaptionButton,
  548. group: 2
  549. };
  550. const recording = {
  551. key: 'recording',
  552. Content: RecordButton,
  553. group: 2
  554. };
  555. const localRecording = {
  556. key: 'localrecording',
  557. Content: LocalRecordingButton,
  558. group: 2
  559. };
  560. const muteEveryone = {
  561. key: 'mute-everyone',
  562. Content: MuteEveryoneButton,
  563. group: 2
  564. };
  565. const muteVideoEveryone = {
  566. key: 'mute-video-everyone',
  567. Content: MuteEveryonesVideoButton,
  568. group: 2
  569. };
  570. const livestreaming = {
  571. key: 'livestreaming',
  572. Content: LiveStreamButton,
  573. group: 2
  574. };
  575. const shareVideo = {
  576. key: 'sharedvideo',
  577. Content: SharedVideoButton,
  578. group: 3
  579. };
  580. const shareAudio = this._showAudioSharingButton() && {
  581. key: 'shareaudio',
  582. Content: ShareAudioButton,
  583. group: 3
  584. };
  585. const etherpad = {
  586. key: 'etherpad',
  587. Content: SharedDocumentButton,
  588. group: 3
  589. };
  590. const virtualBackground = !_screenSharing && checkBlurSupport() && {
  591. key: 'select-background',
  592. Content: VideoBackgroundButton,
  593. group: 3
  594. };
  595. const speakerStats = {
  596. key: 'stats',
  597. Content: SpeakerStatsButton,
  598. group: 3
  599. };
  600. const settings = {
  601. key: 'settings',
  602. Content: SettingsButton,
  603. group: 4
  604. };
  605. const shortcuts = !_isMobile && keyboardShortcut.getEnabled() && {
  606. key: 'shortcuts',
  607. Content: KeyboardShortcutsButton,
  608. group: 4
  609. };
  610. const embed = this._isEmbedMeetingVisible() && {
  611. key: 'embedmeeting',
  612. Content: EmbedMeetingButton,
  613. group: 4
  614. };
  615. const feedback = _feedbackConfigured && {
  616. key: 'feedback',
  617. Content: FeedbackButton,
  618. group: 4
  619. };
  620. const download = {
  621. key: 'download',
  622. Content: DownloadButton,
  623. group: 4
  624. };
  625. const help = {
  626. key: 'help',
  627. Content: HelpButton,
  628. group: 4
  629. };
  630. return {
  631. microphone,
  632. camera,
  633. profile,
  634. desktop,
  635. chat,
  636. raisehand,
  637. participants,
  638. tileview,
  639. videoQuality,
  640. fullscreen,
  641. security,
  642. info,
  643. cc,
  644. recording,
  645. localRecording,
  646. muteEveryone,
  647. muteVideoEveryone,
  648. livestreaming,
  649. shareVideo,
  650. shareAudio,
  651. etherpad,
  652. virtualBackground,
  653. speakerStats,
  654. settings,
  655. shortcuts,
  656. embed,
  657. feedback,
  658. download,
  659. help
  660. };
  661. }
  662. /**
  663. * Returns all buttons that need to be rendered.
  664. *
  665. * @param {Object} state - The redux state.
  666. * @returns {Object} The visible buttons arrays .
  667. */
  668. _getVisibleButtons() {
  669. const {
  670. _clientWidth,
  671. _toolbarButtons
  672. } = this.props;
  673. const buttons = this._getAllButtons();
  674. const isHangupVisible = isToolbarButtonEnabled('hangup', _toolbarButtons);
  675. const { order } = THRESHOLDS.find(({ width }) => _clientWidth > width)
  676. || THRESHOLDS[THRESHOLDS.length - 1];
  677. let sliceIndex = order.length + 2;
  678. const keys = Object.keys(buttons);
  679. const filtered = [
  680. ...order.map(key => buttons[key]),
  681. ...Object.values(buttons).filter((button, index) => !order.includes(keys[index]))
  682. ].filter(Boolean).filter(({ key }) => isToolbarButtonEnabled(key, _toolbarButtons));
  683. if (isHangupVisible) {
  684. sliceIndex -= 1;
  685. }
  686. // This implies that the overflow button will be displayed, so save some space for it.
  687. if (sliceIndex < filtered.length) {
  688. sliceIndex -= 1;
  689. }
  690. return {
  691. mainMenuButtons: filtered.slice(0, sliceIndex),
  692. overflowMenuButtons: filtered.slice(sliceIndex)
  693. };
  694. }
  695. _onMouseOut: () => void;
  696. /**
  697. * Dispatches an action signaling the toolbar is not being hovered.
  698. *
  699. * @private
  700. * @returns {void}
  701. */
  702. _onMouseOut() {
  703. this.props.dispatch(setToolbarHovered(false));
  704. }
  705. _onMouseOver: () => void;
  706. /**
  707. * Dispatches an action signaling the toolbar is being hovered.
  708. *
  709. * @private
  710. * @returns {void}
  711. */
  712. _onMouseOver() {
  713. this.props.dispatch(setToolbarHovered(true));
  714. }
  715. _onSetOverflowVisible: (boolean) => void;
  716. /**
  717. * Sets the visibility of the overflow menu.
  718. *
  719. * @param {boolean} visible - Whether or not the overflow menu should be
  720. * displayed.
  721. * @private
  722. * @returns {void}
  723. */
  724. _onSetOverflowVisible(visible) {
  725. this.props.dispatch(setOverflowMenuVisible(visible));
  726. }
  727. _onShortcutToggleChat: () => void;
  728. /**
  729. * Creates an analytics keyboard shortcut event and dispatches an action for
  730. * toggling the display of chat.
  731. *
  732. * @private
  733. * @returns {void}
  734. */
  735. _onShortcutToggleChat() {
  736. sendAnalytics(createShortcutEvent(
  737. 'toggle.chat',
  738. {
  739. enable: !this.props._chatOpen
  740. }));
  741. // Checks if there was any text selected by the user.
  742. // Used for when we press simultaneously keys for copying
  743. // text messages from the chat board
  744. if (window.getSelection().toString() !== '') {
  745. return false;
  746. }
  747. this._doToggleChat();
  748. }
  749. _onShortcutToggleParticipantsPane: () => void;
  750. /**
  751. * Creates an analytics keyboard shortcut event and dispatches an action for
  752. * toggling the display of the participants pane.
  753. *
  754. * @private
  755. * @returns {void}
  756. */
  757. _onShortcutToggleParticipantsPane() {
  758. sendAnalytics(createShortcutEvent(
  759. 'toggle.participants-pane',
  760. {
  761. enable: !this.props._participantsPaneOpen
  762. }));
  763. this._onToolbarToggleParticipantsPane();
  764. }
  765. _onShortcutToggleVideoQuality: () => void;
  766. /**
  767. * Creates an analytics keyboard shortcut event and dispatches an action for
  768. * toggling the display of Video Quality.
  769. *
  770. * @private
  771. * @returns {void}
  772. */
  773. _onShortcutToggleVideoQuality() {
  774. sendAnalytics(createShortcutEvent('video.quality'));
  775. this._doToggleVideoQuality();
  776. }
  777. _onShortcutToggleTileView: () => void;
  778. /**
  779. * Dispatches an action for toggling the tile view.
  780. *
  781. * @private
  782. * @returns {void}
  783. */
  784. _onShortcutToggleTileView() {
  785. sendAnalytics(createShortcutEvent(
  786. 'toggle.tileview',
  787. {
  788. enable: !this.props._tileViewEnabled
  789. }));
  790. this._doToggleTileView();
  791. }
  792. _onShortcutToggleFullScreen: () => void;
  793. /**
  794. * Creates an analytics keyboard shortcut event and dispatches an action for
  795. * toggling full screen mode.
  796. *
  797. * @private
  798. * @returns {void}
  799. */
  800. _onShortcutToggleFullScreen() {
  801. sendAnalytics(createShortcutEvent(
  802. 'toggle.fullscreen',
  803. {
  804. enable: !this.props._fullScreen
  805. }));
  806. this._doToggleFullScreen();
  807. }
  808. _onShortcutToggleRaiseHand: () => void;
  809. /**
  810. * Creates an analytics keyboard shortcut event and dispatches an action for
  811. * toggling raise hand.
  812. *
  813. * @private
  814. * @returns {void}
  815. */
  816. _onShortcutToggleRaiseHand() {
  817. sendAnalytics(createShortcutEvent(
  818. 'toggle.raise.hand',
  819. ACTION_SHORTCUT_TRIGGERED,
  820. { enable: !this.props._raisedHand }));
  821. this._doToggleRaiseHand();
  822. }
  823. _onShortcutToggleScreenshare: () => void;
  824. /**
  825. * Creates an analytics keyboard shortcut event and dispatches an action for
  826. * toggling screensharing.
  827. *
  828. * @private
  829. * @returns {void}
  830. */
  831. _onShortcutToggleScreenshare() {
  832. sendAnalytics(createShortcutEvent(
  833. 'toggle.screen.sharing',
  834. ACTION_SHORTCUT_TRIGGERED,
  835. {
  836. enable: !this.props._screenSharing
  837. }));
  838. this._doToggleScreenshare();
  839. }
  840. _onTabIn: () => void;
  841. /**
  842. * Toggle the toolbar visibility when tabbing into it.
  843. *
  844. * @returns {void}
  845. */
  846. _onTabIn() {
  847. if (!this.props._visible) {
  848. this.props.dispatch(showToolbox());
  849. }
  850. }
  851. _onToolbarToggleParticipantsPane: () => void;
  852. /**
  853. * Dispatches an action for toggling the participants pane.
  854. *
  855. * @private
  856. * @returns {void}
  857. */
  858. _onToolbarToggleParticipantsPane() {
  859. const { dispatch, _participantsPaneOpen } = this.props;
  860. if (_participantsPaneOpen) {
  861. dispatch(closeParticipantsPane());
  862. } else {
  863. dispatch(openParticipantsPane());
  864. }
  865. }
  866. _onToolbarOpenVideoQuality: () => void;
  867. /**
  868. * Creates an analytics toolbar event and dispatches an action for toggling
  869. * open the video quality dialog.
  870. *
  871. * @private
  872. * @returns {void}
  873. */
  874. _onToolbarOpenVideoQuality() {
  875. sendAnalytics(createToolbarEvent('video.quality'));
  876. this._doOpenVideoQuality();
  877. }
  878. _onToolbarToggleChat: () => void;
  879. /**
  880. * Creates an analytics toolbar event and dispatches an action for toggling
  881. * the display of chat.
  882. *
  883. * @private
  884. * @returns {void}
  885. */
  886. _onToolbarToggleChat() {
  887. sendAnalytics(createToolbarEvent(
  888. 'toggle.chat',
  889. {
  890. enable: !this.props._chatOpen
  891. }));
  892. this._closeOverflowMenuIfOpen();
  893. this._doToggleChat();
  894. }
  895. _onToolbarToggleFullScreen: () => void;
  896. /**
  897. * Creates an analytics toolbar event and dispatches an action for toggling
  898. * full screen mode.
  899. *
  900. * @private
  901. * @returns {void}
  902. */
  903. _onToolbarToggleFullScreen() {
  904. sendAnalytics(createToolbarEvent(
  905. 'toggle.fullscreen',
  906. {
  907. enable: !this.props._fullScreen
  908. }));
  909. this._closeOverflowMenuIfOpen();
  910. this._doToggleFullScreen();
  911. }
  912. _onToolbarToggleScreenshare: () => void;
  913. /**
  914. * Creates an analytics toolbar event and dispatches an action for toggling
  915. * screensharing.
  916. *
  917. * @private
  918. * @returns {void}
  919. */
  920. _onToolbarToggleScreenshare() {
  921. sendAnalytics(createToolbarEvent(
  922. 'toggle.screen.sharing',
  923. ACTION_SHORTCUT_TRIGGERED,
  924. { enable: !this.props._screenSharing }));
  925. this._closeOverflowMenuIfOpen();
  926. this._doToggleScreenshare();
  927. }
  928. /**
  929. * Returns true if the audio sharing button should be visible and
  930. * false otherwise.
  931. *
  932. * @returns {boolean}
  933. */
  934. _showAudioSharingButton() {
  935. const {
  936. _desktopSharingEnabled
  937. } = this.props;
  938. return _desktopSharingEnabled && isScreenAudioSupported();
  939. }
  940. /**
  941. * Returns true if the desktop sharing button should be visible and
  942. * false otherwise.
  943. *
  944. * @returns {boolean}
  945. */
  946. _showDesktopSharingButton() {
  947. const {
  948. _desktopSharingEnabled,
  949. _desktopSharingDisabledTooltipKey
  950. } = this.props;
  951. return _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  952. }
  953. /**
  954. * Returns true if the embed meeting button is visible and false otherwise.
  955. *
  956. * @returns {boolean}
  957. */
  958. _isEmbedMeetingVisible() {
  959. return !this.props._isVpaasMeeting
  960. && !this.props._isMobile;
  961. }
  962. /**
  963. * Returns true if the profile button is visible and false otherwise.
  964. *
  965. * @returns {boolean}
  966. */
  967. _isProfileVisible() {
  968. return !this.props._isProfileDisabled;
  969. }
  970. /**
  971. * Renders the toolbox content.
  972. *
  973. * @returns {ReactElement}
  974. */
  975. _renderToolboxContent() {
  976. const {
  977. _isMobile,
  978. _overflowMenuVisible,
  979. _toolbarButtons,
  980. t
  981. } = this.props;
  982. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  983. const containerClassName = `toolbox-content${_isMobile ? ' toolbox-content-mobile' : ''}`;
  984. const { mainMenuButtons, overflowMenuButtons } = this._getVisibleButtons();
  985. return (
  986. <div className = { containerClassName }>
  987. <div
  988. className = 'toolbox-content-wrapper'
  989. onFocus = { this._onTabIn }
  990. onMouseOut = { this._onMouseOut }
  991. onMouseOver = { this._onMouseOver }>
  992. <div className = 'toolbox-content-items'>
  993. {mainMenuButtons.map(({ Content, key, ...rest }) => Content !== Separator && (
  994. <Content
  995. { ...rest }
  996. key = { key } />))}
  997. {Boolean(overflowMenuButtons.length) && (
  998. <OverflowMenuButton
  999. ariaControls = 'overflow-menu'
  1000. isOpen = { _overflowMenuVisible }
  1001. key = 'overflow-menu'
  1002. onVisibilityChange = { this._onSetOverflowVisible }
  1003. showMobileReactions = {
  1004. overflowMenuButtons.find(({ key }) => key === 'raisehand')
  1005. }>
  1006. <ul
  1007. aria-label = { t(toolbarAccLabel) }
  1008. className = 'overflow-menu'
  1009. id = 'overflow-menu'
  1010. onKeyDown = { this._onEscKey }
  1011. role = 'menu'>
  1012. {overflowMenuButtons.map(({ group, key, Content, ...rest }, index, arr) => {
  1013. const showSeparator = index > 0 && arr[index - 1].group !== group;
  1014. return key !== 'raisehand'
  1015. && <>
  1016. {showSeparator && <Separator key = { `hr${group}` } />}
  1017. <Content
  1018. { ...rest }
  1019. key = { key }
  1020. showLabel = { true } />
  1021. </>
  1022. ;
  1023. })}
  1024. </ul>
  1025. </OverflowMenuButton>
  1026. )}
  1027. <HangupButton
  1028. customClass = 'hangup-button'
  1029. key = 'hangup-button'
  1030. visible = { isToolbarButtonEnabled('hangup', _toolbarButtons) } />
  1031. </div>
  1032. </div>
  1033. </div>
  1034. );
  1035. }
  1036. }
  1037. /**
  1038. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  1039. * props.
  1040. *
  1041. * @param {Object} state - The redux store/state.
  1042. * @private
  1043. * @returns {{}}
  1044. */
  1045. function _mapStateToProps(state) {
  1046. const { conference } = state['features/base/conference'];
  1047. let desktopSharingEnabled = JitsiMeetJS.isDesktopSharingEnabled();
  1048. const {
  1049. callStatsID,
  1050. enableFeaturesBasedOnToken
  1051. } = state['features/base/config'];
  1052. const {
  1053. fullScreen,
  1054. overflowMenuVisible
  1055. } = state['features/toolbox'];
  1056. const localParticipant = getLocalParticipant(state);
  1057. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  1058. const { clientWidth } = state['features/base/responsive-ui'];
  1059. let desktopSharingDisabledTooltipKey;
  1060. if (enableFeaturesBasedOnToken) {
  1061. if (desktopSharingEnabled) {
  1062. // we enable desktop sharing if any participant already have this
  1063. // feature enabled and if the user supports it.
  1064. desktopSharingEnabled = haveParticipantWithScreenSharingFeature(state);
  1065. desktopSharingDisabledTooltipKey = 'dialog.shareYourScreenDisabled';
  1066. }
  1067. }
  1068. return {
  1069. _chatOpen: state['features/chat'].isOpen,
  1070. _clientWidth: clientWidth,
  1071. _conference: conference,
  1072. _desktopSharingEnabled: desktopSharingEnabled,
  1073. _backgroundType: state['features/virtual-background'].backgroundType,
  1074. _virtualSource: state['features/virtual-background'].virtualSource,
  1075. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  1076. _dialog: Boolean(state['features/base/dialog'].component),
  1077. _feedbackConfigured: Boolean(callStatsID),
  1078. _isProfileDisabled: Boolean(state['features/base/config'].disableProfile),
  1079. _isMobile: isMobileBrowser(),
  1080. _isVpaasMeeting: isVpaasMeeting(state),
  1081. _fullScreen: fullScreen,
  1082. _tileViewEnabled: shouldDisplayTileView(state),
  1083. _localParticipantID: localParticipant?.id,
  1084. _localVideo: localVideo,
  1085. _overflowMenuVisible: overflowMenuVisible,
  1086. _participantsPaneOpen: getParticipantsPaneOpen(state),
  1087. _raisedHand: localParticipant?.raisedHand,
  1088. _screenSharing: isScreenVideoShared(state),
  1089. _toolbarButtons: getToolbarButtons(state),
  1090. _visible: isToolboxVisible(state),
  1091. _visibleButtons: getToolbarButtons(state)
  1092. };
  1093. }
  1094. export default translate(connect(_mapStateToProps)(Toolbox));