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

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