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 37KB

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