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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  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 { InviteButton } from '../../../invite/components/add-people-dialog';
  30. import { isVpaasMeeting } from '../../../jaas/functions';
  31. import { KeyboardShortcutsButton } from '../../../keyboard-shortcuts';
  32. import { LocalRecordingButton } from '../../../local-recording';
  33. import {
  34. close as closeParticipantsPane,
  35. open as openParticipantsPane
  36. } from '../../../participants-pane/actions';
  37. import ParticipantsPaneButton from '../../../participants-pane/components/ParticipantsPaneButton';
  38. import { getParticipantsPaneOpen } from '../../../participants-pane/functions';
  39. import { addReactionToBuffer } from '../../../reactions/actions.any';
  40. import { ReactionsMenuButton } from '../../../reactions/components';
  41. import { REACTIONS } from '../../../reactions/constants';
  42. import {
  43. LiveStreamButton,
  44. RecordButton
  45. } from '../../../recording';
  46. import {
  47. isScreenAudioSupported,
  48. isScreenVideoShared,
  49. ShareAudioButton,
  50. startScreenShareFlow
  51. } from '../../../screen-share/';
  52. import SecurityDialogButton from '../../../security/components/security-dialog/SecurityDialogButton';
  53. import { SettingsButton } from '../../../settings';
  54. import { SharedVideoButton } from '../../../shared-video/components';
  55. import { SpeakerStatsButton } from '../../../speaker-stats';
  56. import {
  57. ClosedCaptionButton
  58. } from '../../../subtitles';
  59. import {
  60. TileViewButton,
  61. shouldDisplayTileView,
  62. toggleTileView
  63. } from '../../../video-layout';
  64. import { VideoQualityDialog, VideoQualityButton } from '../../../video-quality/components';
  65. import { VideoBackgroundButton } from '../../../virtual-background';
  66. import { toggleBackgroundEffect } from '../../../virtual-background/actions';
  67. import { VIRTUAL_BACKGROUND_TYPE } from '../../../virtual-background/constants';
  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. * Returns the selected virtual source object.
  185. */
  186. _virtualSource: Object,
  187. /**
  188. * Whether or not reactions feature is enabled.
  189. */
  190. _reactionsEnabled: boolean,
  191. /**
  192. * Invoked to active other features of the app.
  193. */
  194. dispatch: Function,
  195. /**
  196. * Invoked to obtain translated strings.
  197. */
  198. t: Function,
  199. /**
  200. * Explicitly passed array with the buttons which this Toolbox should display.
  201. */
  202. toolbarButtons: Array<string>,
  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, _toolbarButtons } = this.props;
  358. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  359. _toolbarButtons.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. Content: ParticipantsPaneButton,
  529. handleClick: this._onToolbarToggleParticipantsPane,
  530. group: 2
  531. };
  532. const invite = {
  533. key: 'invite',
  534. Content: InviteButton,
  535. group: 2
  536. };
  537. const tileview = {
  538. key: 'tileview',
  539. Content: TileViewButton,
  540. group: 2
  541. };
  542. const toggleCamera = {
  543. key: 'toggle-camera',
  544. Content: ToggleCameraButton,
  545. group: 2
  546. };
  547. const videoQuality = {
  548. key: 'videoquality',
  549. Content: VideoQualityButton,
  550. handleClick: this._onToolbarOpenVideoQuality,
  551. group: 2
  552. };
  553. const fullscreen = !_isMobile && {
  554. key: 'fullscreen',
  555. Content: FullscreenButton,
  556. handleClick: this._onToolbarToggleFullScreen,
  557. group: 2
  558. };
  559. const security = {
  560. key: 'security',
  561. alias: 'info',
  562. Content: SecurityDialogButton,
  563. group: 2
  564. };
  565. const cc = {
  566. key: 'closedcaptions',
  567. Content: ClosedCaptionButton,
  568. group: 2
  569. };
  570. const recording = {
  571. key: 'recording',
  572. Content: RecordButton,
  573. group: 2
  574. };
  575. const localRecording = {
  576. key: 'localrecording',
  577. Content: LocalRecordingButton,
  578. group: 2
  579. };
  580. const livestreaming = {
  581. key: 'livestreaming',
  582. Content: LiveStreamButton,
  583. group: 2
  584. };
  585. const muteEveryone = {
  586. key: 'mute-everyone',
  587. Content: MuteEveryoneButton,
  588. group: 2
  589. };
  590. const muteVideoEveryone = {
  591. key: 'mute-video-everyone',
  592. Content: MuteEveryonesVideoButton,
  593. group: 2
  594. };
  595. const shareVideo = {
  596. key: 'sharedvideo',
  597. Content: SharedVideoButton,
  598. group: 3
  599. };
  600. const shareAudio = this._showAudioSharingButton() && {
  601. key: 'shareaudio',
  602. Content: ShareAudioButton,
  603. group: 3
  604. };
  605. const etherpad = {
  606. key: 'etherpad',
  607. Content: SharedDocumentButton,
  608. group: 3
  609. };
  610. const virtualBackground = !_screenSharing && {
  611. key: 'select-background',
  612. Content: VideoBackgroundButton,
  613. group: 3
  614. };
  615. const speakerStats = {
  616. key: 'stats',
  617. Content: SpeakerStatsButton,
  618. group: 3
  619. };
  620. const settings = {
  621. key: 'settings',
  622. Content: SettingsButton,
  623. group: 4
  624. };
  625. const shortcuts = !_isMobile && keyboardShortcut.getEnabled() && {
  626. key: 'shortcuts',
  627. Content: KeyboardShortcutsButton,
  628. group: 4
  629. };
  630. const embed = this._isEmbedMeetingVisible() && {
  631. key: 'embedmeeting',
  632. Content: EmbedMeetingButton,
  633. group: 4
  634. };
  635. const feedback = _feedbackConfigured && {
  636. key: 'feedback',
  637. Content: FeedbackButton,
  638. group: 4
  639. };
  640. const download = {
  641. key: 'download',
  642. Content: DownloadButton,
  643. group: 4
  644. };
  645. const help = {
  646. key: 'help',
  647. Content: HelpButton,
  648. group: 4
  649. };
  650. return {
  651. microphone,
  652. camera,
  653. profile,
  654. desktop,
  655. chat,
  656. raisehand,
  657. participants,
  658. invite,
  659. tileview,
  660. toggleCamera,
  661. videoQuality,
  662. fullscreen,
  663. security,
  664. cc,
  665. recording,
  666. localRecording,
  667. livestreaming,
  668. muteEveryone,
  669. muteVideoEveryone,
  670. shareVideo,
  671. shareAudio,
  672. etherpad,
  673. virtualBackground,
  674. speakerStats,
  675. settings,
  676. shortcuts,
  677. embed,
  678. feedback,
  679. download,
  680. help
  681. };
  682. }
  683. /**
  684. * Returns all buttons that need to be rendered.
  685. *
  686. * @param {Object} state - The redux state.
  687. * @returns {Object} The visible buttons arrays .
  688. */
  689. _getVisibleButtons() {
  690. const {
  691. _clientWidth,
  692. _toolbarButtons
  693. } = this.props;
  694. const buttons = this._getAllButtons();
  695. const isHangupVisible = isToolbarButtonEnabled('hangup', _toolbarButtons);
  696. const { order } = THRESHOLDS.find(({ width }) => _clientWidth > width)
  697. || THRESHOLDS[THRESHOLDS.length - 1];
  698. let sliceIndex = order.length + 2;
  699. const keys = Object.keys(buttons);
  700. const filtered = [
  701. ...order.map(key => buttons[key]),
  702. ...Object.values(buttons).filter((button, index) => !order.includes(keys[index]))
  703. ].filter(Boolean).filter(({ key, alias = NOT_APPLICABLE }) =>
  704. isToolbarButtonEnabled(key, _toolbarButtons) || isToolbarButtonEnabled(alias, _toolbarButtons));
  705. if (isHangupVisible) {
  706. sliceIndex -= 1;
  707. }
  708. // This implies that the overflow button will be displayed, so save some space for it.
  709. if (sliceIndex < filtered.length) {
  710. sliceIndex -= 1;
  711. }
  712. return {
  713. mainMenuButtons: filtered.slice(0, sliceIndex),
  714. overflowMenuButtons: filtered.slice(sliceIndex)
  715. };
  716. }
  717. _onMouseOut: () => void;
  718. /**
  719. * Dispatches an action signaling the toolbar is not being hovered.
  720. *
  721. * @private
  722. * @returns {void}
  723. */
  724. _onMouseOut() {
  725. this.props.dispatch(setToolbarHovered(false));
  726. }
  727. _onMouseOver: () => void;
  728. /**
  729. * Dispatches an action signaling the toolbar is being hovered.
  730. *
  731. * @private
  732. * @returns {void}
  733. */
  734. _onMouseOver() {
  735. this.props.dispatch(setToolbarHovered(true));
  736. }
  737. _onSetOverflowVisible: (boolean) => void;
  738. /**
  739. * Sets the visibility of the overflow menu.
  740. *
  741. * @param {boolean} visible - Whether or not the overflow menu should be
  742. * displayed.
  743. * @private
  744. * @returns {void}
  745. */
  746. _onSetOverflowVisible(visible) {
  747. this.props.dispatch(setOverflowMenuVisible(visible));
  748. }
  749. _onShortcutToggleChat: () => void;
  750. /**
  751. * Creates an analytics keyboard shortcut event and dispatches an action for
  752. * toggling the display of chat.
  753. *
  754. * @private
  755. * @returns {void}
  756. */
  757. _onShortcutToggleChat() {
  758. sendAnalytics(createShortcutEvent(
  759. 'toggle.chat',
  760. {
  761. enable: !this.props._chatOpen
  762. }));
  763. // Checks if there was any text selected by the user.
  764. // Used for when we press simultaneously keys for copying
  765. // text messages from the chat board
  766. if (window.getSelection().toString() !== '') {
  767. return false;
  768. }
  769. this._doToggleChat();
  770. }
  771. _onShortcutToggleParticipantsPane: () => void;
  772. /**
  773. * Creates an analytics keyboard shortcut event and dispatches an action for
  774. * toggling the display of the participants pane.
  775. *
  776. * @private
  777. * @returns {void}
  778. */
  779. _onShortcutToggleParticipantsPane() {
  780. sendAnalytics(createShortcutEvent(
  781. 'toggle.participants-pane',
  782. {
  783. enable: !this.props._participantsPaneOpen
  784. }));
  785. this._onToolbarToggleParticipantsPane();
  786. }
  787. _onShortcutToggleVideoQuality: () => void;
  788. /**
  789. * Creates an analytics keyboard shortcut event and dispatches an action for
  790. * toggling the display of Video Quality.
  791. *
  792. * @private
  793. * @returns {void}
  794. */
  795. _onShortcutToggleVideoQuality() {
  796. sendAnalytics(createShortcutEvent('video.quality'));
  797. this._doToggleVideoQuality();
  798. }
  799. _onShortcutToggleTileView: () => void;
  800. /**
  801. * Dispatches an action for toggling the tile view.
  802. *
  803. * @private
  804. * @returns {void}
  805. */
  806. _onShortcutToggleTileView() {
  807. sendAnalytics(createShortcutEvent(
  808. 'toggle.tileview',
  809. {
  810. enable: !this.props._tileViewEnabled
  811. }));
  812. this._doToggleTileView();
  813. }
  814. _onShortcutToggleFullScreen: () => void;
  815. /**
  816. * Creates an analytics keyboard shortcut event and dispatches an action for
  817. * toggling full screen mode.
  818. *
  819. * @private
  820. * @returns {void}
  821. */
  822. _onShortcutToggleFullScreen() {
  823. sendAnalytics(createShortcutEvent(
  824. 'toggle.fullscreen',
  825. {
  826. enable: !this.props._fullScreen
  827. }));
  828. this._doToggleFullScreen();
  829. }
  830. _onShortcutToggleRaiseHand: () => void;
  831. /**
  832. * Creates an analytics keyboard shortcut event and dispatches an action for
  833. * toggling raise hand.
  834. *
  835. * @private
  836. * @returns {void}
  837. */
  838. _onShortcutToggleRaiseHand() {
  839. sendAnalytics(createShortcutEvent(
  840. 'toggle.raise.hand',
  841. ACTION_SHORTCUT_TRIGGERED,
  842. { enable: !this.props._raisedHand }));
  843. this._doToggleRaiseHand();
  844. }
  845. _onShortcutToggleScreenshare: () => void;
  846. /**
  847. * Creates an analytics keyboard shortcut event and dispatches an action for
  848. * toggling screensharing.
  849. *
  850. * @private
  851. * @returns {void}
  852. */
  853. _onShortcutToggleScreenshare() {
  854. sendAnalytics(createShortcutEvent(
  855. 'toggle.screen.sharing',
  856. ACTION_SHORTCUT_TRIGGERED,
  857. {
  858. enable: !this.props._screenSharing
  859. }));
  860. this._doToggleScreenshare();
  861. }
  862. _onTabIn: () => void;
  863. /**
  864. * Toggle the toolbar visibility when tabbing into it.
  865. *
  866. * @returns {void}
  867. */
  868. _onTabIn() {
  869. if (!this.props._visible) {
  870. this.props.dispatch(showToolbox());
  871. }
  872. }
  873. _onToolbarToggleParticipantsPane: () => void;
  874. /**
  875. * Dispatches an action for toggling the participants pane.
  876. *
  877. * @private
  878. * @returns {void}
  879. */
  880. _onToolbarToggleParticipantsPane() {
  881. const { dispatch, _participantsPaneOpen } = this.props;
  882. if (_participantsPaneOpen) {
  883. dispatch(closeParticipantsPane());
  884. } else {
  885. dispatch(openParticipantsPane());
  886. }
  887. }
  888. _onToolbarOpenVideoQuality: () => void;
  889. /**
  890. * Creates an analytics toolbar event and dispatches an action for toggling
  891. * open the video quality dialog.
  892. *
  893. * @private
  894. * @returns {void}
  895. */
  896. _onToolbarOpenVideoQuality() {
  897. sendAnalytics(createToolbarEvent('video.quality'));
  898. this._doOpenVideoQuality();
  899. }
  900. _onToolbarToggleChat: () => void;
  901. /**
  902. * Creates an analytics toolbar event and dispatches an action for toggling
  903. * the display of chat.
  904. *
  905. * @private
  906. * @returns {void}
  907. */
  908. _onToolbarToggleChat() {
  909. sendAnalytics(createToolbarEvent(
  910. 'toggle.chat',
  911. {
  912. enable: !this.props._chatOpen
  913. }));
  914. this._closeOverflowMenuIfOpen();
  915. this._doToggleChat();
  916. }
  917. _onToolbarToggleFullScreen: () => void;
  918. /**
  919. * Creates an analytics toolbar event and dispatches an action for toggling
  920. * full screen mode.
  921. *
  922. * @private
  923. * @returns {void}
  924. */
  925. _onToolbarToggleFullScreen() {
  926. sendAnalytics(createToolbarEvent(
  927. 'toggle.fullscreen',
  928. {
  929. enable: !this.props._fullScreen
  930. }));
  931. this._closeOverflowMenuIfOpen();
  932. this._doToggleFullScreen();
  933. }
  934. _onToolbarToggleRaiseHand: () => void;
  935. /**
  936. * Creates an analytics toolbar event and dispatches an action for toggling
  937. * raise hand.
  938. *
  939. * @private
  940. * @returns {void}
  941. */
  942. _onToolbarToggleRaiseHand() {
  943. sendAnalytics(createToolbarEvent(
  944. 'raise.hand',
  945. { enable: !this.props._raisedHand }));
  946. this._doToggleRaiseHand();
  947. }
  948. _onToolbarToggleScreenshare: () => void;
  949. /**
  950. * Creates an analytics toolbar event and dispatches an action for toggling
  951. * screensharing.
  952. *
  953. * @private
  954. * @returns {void}
  955. */
  956. _onToolbarToggleScreenshare() {
  957. sendAnalytics(createToolbarEvent(
  958. 'toggle.screen.sharing',
  959. ACTION_SHORTCUT_TRIGGERED,
  960. { enable: !this.props._screenSharing }));
  961. this._closeOverflowMenuIfOpen();
  962. this._doToggleScreenshare();
  963. }
  964. /**
  965. * Returns true if the audio sharing button should be visible and
  966. * false otherwise.
  967. *
  968. * @returns {boolean}
  969. */
  970. _showAudioSharingButton() {
  971. const {
  972. _desktopSharingEnabled
  973. } = this.props;
  974. return _desktopSharingEnabled && isScreenAudioSupported();
  975. }
  976. /**
  977. * Returns true if the desktop sharing button should be visible and
  978. * false otherwise.
  979. *
  980. * @returns {boolean}
  981. */
  982. _showDesktopSharingButton() {
  983. const {
  984. _desktopSharingEnabled,
  985. _desktopSharingDisabledTooltipKey
  986. } = this.props;
  987. return _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  988. }
  989. /**
  990. * Returns true if the embed meeting button is visible and false otherwise.
  991. *
  992. * @returns {boolean}
  993. */
  994. _isEmbedMeetingVisible() {
  995. return !this.props._isVpaasMeeting
  996. && !this.props._isMobile;
  997. }
  998. /**
  999. * Returns true if the profile button is visible and false otherwise.
  1000. *
  1001. * @returns {boolean}
  1002. */
  1003. _isProfileVisible() {
  1004. return !this.props._isProfileDisabled;
  1005. }
  1006. /**
  1007. * Renders the toolbox content.
  1008. *
  1009. * @returns {ReactElement}
  1010. */
  1011. _renderToolboxContent() {
  1012. const {
  1013. _isMobile,
  1014. _overflowMenuVisible,
  1015. _toolbarButtons,
  1016. t,
  1017. _reactionsEnabled
  1018. } = this.props;
  1019. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  1020. const containerClassName = `toolbox-content${_isMobile ? ' toolbox-content-mobile' : ''}`;
  1021. const { mainMenuButtons, overflowMenuButtons } = this._getVisibleButtons();
  1022. return (
  1023. <div className = { containerClassName }>
  1024. <div
  1025. className = 'toolbox-content-wrapper'
  1026. onFocus = { this._onTabIn }
  1027. { ...(_isMobile ? {} : {
  1028. onMouseOut: this._onMouseOut,
  1029. onMouseOver: this._onMouseOver
  1030. }) }>
  1031. <DominantSpeakerName />
  1032. <div className = 'toolbox-content-items'>
  1033. {mainMenuButtons.map(({ Content, key, ...rest }) => Content !== Separator && (
  1034. <Content
  1035. { ...rest }
  1036. key = { key } />))}
  1037. {Boolean(overflowMenuButtons.length) && (
  1038. <OverflowMenuButton
  1039. ariaControls = 'overflow-menu'
  1040. isOpen = { _overflowMenuVisible }
  1041. key = 'overflow-menu'
  1042. onVisibilityChange = { this._onSetOverflowVisible }
  1043. showMobileReactions = {
  1044. _reactionsEnabled && overflowMenuButtons.find(({ key }) => key === 'raisehand')
  1045. }>
  1046. <ul
  1047. aria-label = { t(toolbarAccLabel) }
  1048. className = 'overflow-menu'
  1049. id = 'overflow-menu'
  1050. onKeyDown = { this._onEscKey }
  1051. role = 'menu'>
  1052. {overflowMenuButtons.map(({ group, key, Content, ...rest }, index, arr) => {
  1053. const showSeparator = index > 0 && arr[index - 1].group !== group;
  1054. return (key !== 'raisehand' || !_reactionsEnabled)
  1055. && <>
  1056. {showSeparator && <Separator key = { `hr${group}` } />}
  1057. <Content
  1058. { ...rest }
  1059. key = { key }
  1060. showLabel = { true } />
  1061. </>
  1062. ;
  1063. })}
  1064. </ul>
  1065. </OverflowMenuButton>
  1066. )}
  1067. <HangupButton
  1068. customClass = 'hangup-button'
  1069. key = 'hangup-button'
  1070. visible = { isToolbarButtonEnabled('hangup', _toolbarButtons) } />
  1071. </div>
  1072. </div>
  1073. </div>
  1074. );
  1075. }
  1076. }
  1077. /**
  1078. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  1079. * props.
  1080. *
  1081. * @param {Object} state - The redux store/state.
  1082. * @param {Object} ownProps - The props explicitly passed.
  1083. * @private
  1084. * @returns {{}}
  1085. */
  1086. function _mapStateToProps(state, ownProps) {
  1087. const { conference } = state['features/base/conference'];
  1088. let desktopSharingEnabled = JitsiMeetJS.isDesktopSharingEnabled();
  1089. const {
  1090. callStatsID,
  1091. enableFeaturesBasedOnToken
  1092. } = state['features/base/config'];
  1093. const {
  1094. fullScreen,
  1095. overflowMenuVisible
  1096. } = state['features/toolbox'];
  1097. const localParticipant = getLocalParticipant(state);
  1098. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  1099. const { clientWidth } = state['features/base/responsive-ui'];
  1100. const { enableReactions } = state['features/base/config'];
  1101. let desktopSharingDisabledTooltipKey;
  1102. if (enableFeaturesBasedOnToken) {
  1103. if (desktopSharingEnabled) {
  1104. // we enable desktop sharing if any participant already have this
  1105. // feature enabled and if the user supports it.
  1106. desktopSharingEnabled = haveParticipantWithScreenSharingFeature(state);
  1107. desktopSharingDisabledTooltipKey = 'dialog.shareYourScreenDisabled';
  1108. }
  1109. }
  1110. let { toolbarButtons } = ownProps;
  1111. const stateToolbarButtons = getToolbarButtons(state);
  1112. if (toolbarButtons) {
  1113. toolbarButtons = toolbarButtons.filter(name => isToolbarButtonEnabled(name, stateToolbarButtons));
  1114. } else {
  1115. toolbarButtons = stateToolbarButtons;
  1116. }
  1117. return {
  1118. _chatOpen: state['features/chat'].isOpen,
  1119. _clientWidth: clientWidth,
  1120. _conference: conference,
  1121. _desktopSharingEnabled: desktopSharingEnabled,
  1122. _backgroundType: state['features/virtual-background'].backgroundType,
  1123. _virtualSource: state['features/virtual-background'].virtualSource,
  1124. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  1125. _dialog: Boolean(state['features/base/dialog'].component),
  1126. _feedbackConfigured: Boolean(callStatsID),
  1127. _isProfileDisabled: Boolean(state['features/base/config'].disableProfile),
  1128. _isMobile: isMobileBrowser(),
  1129. _isVpaasMeeting: isVpaasMeeting(state),
  1130. _fullScreen: fullScreen,
  1131. _tileViewEnabled: shouldDisplayTileView(state),
  1132. _localParticipantID: localParticipant?.id,
  1133. _localVideo: localVideo,
  1134. _overflowMenuVisible: overflowMenuVisible,
  1135. _participantsPaneOpen: getParticipantsPaneOpen(state),
  1136. _raisedHand: localParticipant?.raisedHand,
  1137. _screenSharing: isScreenVideoShared(state),
  1138. _toolbarButtons: toolbarButtons,
  1139. _visible: isToolboxVisible(state),
  1140. _reactionsEnabled: enableReactions
  1141. };
  1142. }
  1143. export default translate(connect(_mapStateToProps)(Toolbox));