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

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