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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  1. // @flow
  2. import React, { Component } from 'react';
  3. import {
  4. ACTION_SHORTCUT_TRIGGERED,
  5. createShortcutEvent,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import { openDialog, toggleDialog } from '../../../base/dialog';
  10. import { translate } from '../../../base/i18n';
  11. import {
  12. IconChat,
  13. IconExitFullScreen,
  14. IconFeedback,
  15. IconFullScreen,
  16. IconInvite,
  17. IconOpenInNew,
  18. IconPresentation,
  19. IconRaisedHand,
  20. IconRec,
  21. IconShareDesktop,
  22. IconShareVideo
  23. } from '../../../base/icons';
  24. import {
  25. getLocalParticipant,
  26. getParticipants,
  27. participantUpdated
  28. } from '../../../base/participants';
  29. import { connect, equals } from '../../../base/redux';
  30. import { OverflowMenuItem } from '../../../base/toolbox';
  31. import { getLocalVideoTrack, toggleScreensharing } from '../../../base/tracks';
  32. import { VideoBlurButton } from '../../../blur';
  33. import { ChatCounter, toggleChat } from '../../../chat';
  34. import { SharedDocumentButton } from '../../../etherpad';
  35. import { openFeedbackDialog } from '../../../feedback';
  36. import {
  37. beginAddPeople,
  38. InfoDialogButton,
  39. isAddPeopleEnabled,
  40. isDialOutEnabled
  41. } from '../../../invite';
  42. import { openKeyboardShortcutsDialog } from '../../../keyboard-shortcuts';
  43. import {
  44. LocalRecordingButton,
  45. LocalRecordingInfoDialog
  46. } from '../../../local-recording';
  47. import {
  48. LiveStreamButton,
  49. RecordButton
  50. } from '../../../recording';
  51. import {
  52. SETTINGS_TABS,
  53. SettingsButton,
  54. openSettingsDialog
  55. } from '../../../settings';
  56. import { toggleSharedVideo } from '../../../shared-video';
  57. import { SpeakerStats } from '../../../speaker-stats';
  58. import {
  59. TileViewButton,
  60. toggleTileView
  61. } from '../../../video-layout';
  62. import {
  63. OverflowMenuVideoQualityItem,
  64. VideoQualityDialog
  65. } from '../../../video-quality';
  66. import {
  67. setFullScreen,
  68. setOverflowMenuVisible,
  69. setToolbarHovered
  70. } from '../../actions';
  71. import AudioMuteButton from '../AudioMuteButton';
  72. import DownloadButton from '../DownloadButton';
  73. import { isToolboxVisible } from '../../functions';
  74. import HangupButton from '../HangupButton';
  75. import HelpButton from '../HelpButton';
  76. import OverflowMenuButton from './OverflowMenuButton';
  77. import OverflowMenuProfileItem from './OverflowMenuProfileItem';
  78. import ToolbarButton from './ToolbarButton';
  79. import VideoMuteButton from '../VideoMuteButton';
  80. import {
  81. ClosedCaptionButton
  82. } from '../../../subtitles';
  83. /**
  84. * The type of the React {@code Component} props of {@link Toolbox}.
  85. */
  86. type Props = {
  87. /**
  88. * Whether or not the chat feature is currently displayed.
  89. */
  90. _chatOpen: boolean,
  91. /**
  92. * The {@code JitsiConference} for the current conference.
  93. */
  94. _conference: Object,
  95. /**
  96. * The tooltip key to use when screensharing is disabled. Or undefined
  97. * if non to be shown and the button to be hidden.
  98. */
  99. _desktopSharingDisabledTooltipKey: boolean,
  100. /**
  101. * Whether or not screensharing is initialized.
  102. */
  103. _desktopSharingEnabled: boolean,
  104. /**
  105. * Whether or not a dialog is displayed.
  106. */
  107. _dialog: boolean,
  108. /**
  109. * Whether or not call feedback can be sent.
  110. */
  111. _feedbackConfigured: boolean,
  112. /**
  113. * Whether or not the app is currently in full screen.
  114. */
  115. _fullScreen: boolean,
  116. /**
  117. * Whether or not the tile view is enabled.
  118. */
  119. _tileViewEnabled: boolean,
  120. /**
  121. * Whether or not invite should be hidden, regardless of feature
  122. * availability.
  123. */
  124. _hideInviteButton: boolean,
  125. /**
  126. * Whether or not the current user is logged in through a JWT.
  127. */
  128. _isGuest: boolean,
  129. /**
  130. * The ID of the local participant.
  131. */
  132. _localParticipantID: String,
  133. /**
  134. * The subsection of Redux state for local recording
  135. */
  136. _localRecState: Object,
  137. /**
  138. * Whether or not the overflow menu is visible.
  139. */
  140. _overflowMenuVisible: boolean,
  141. /**
  142. * Whether or not the local participant's hand is raised.
  143. */
  144. _raisedHand: boolean,
  145. /**
  146. * Whether or not the local participant is screensharing.
  147. */
  148. _screensharing: boolean,
  149. /**
  150. * Whether or not the local participant is sharing a YouTube video.
  151. */
  152. _sharingVideo: boolean,
  153. /**
  154. * Flag showing whether toolbar is visible.
  155. */
  156. _visible: boolean,
  157. /**
  158. * Set with the buttons which this Toolbox should display.
  159. */
  160. _visibleButtons: Set<string>,
  161. /**
  162. * Invoked to active other features of the app.
  163. */
  164. dispatch: Function,
  165. /**
  166. * Invoked to obtain translated strings.
  167. */
  168. t: Function
  169. };
  170. /**
  171. * The type of the React {@code Component} state of {@link Toolbox}.
  172. */
  173. type State = {
  174. /**
  175. * The width of the browser's window.
  176. */
  177. windowWidth: number
  178. };
  179. declare var APP: Object;
  180. declare var interfaceConfig: Object;
  181. // XXX: We are not currently using state here, but in the future, when
  182. // interfaceConfig is part of redux we will. This will have to be retrieved from the store.
  183. const visibleButtons = new Set(interfaceConfig.TOOLBAR_BUTTONS);
  184. /**
  185. * Implements the conference toolbox on React/Web.
  186. *
  187. * @extends Component
  188. */
  189. class Toolbox extends Component<Props, State> {
  190. /**
  191. * Initializes a new {@code Toolbox} instance.
  192. *
  193. * @param {Props} props - The read-only React {@code Component} props with
  194. * which the new instance is to be initialized.
  195. */
  196. constructor(props: Props) {
  197. super(props);
  198. // Bind event handlers so they are only bound once per instance.
  199. this._onMouseOut = this._onMouseOut.bind(this);
  200. this._onMouseOver = this._onMouseOver.bind(this);
  201. this._onResize = this._onResize.bind(this);
  202. this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
  203. this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
  204. this._onShortcutToggleFullScreen = this._onShortcutToggleFullScreen.bind(this);
  205. this._onShortcutToggleRaiseHand = this._onShortcutToggleRaiseHand.bind(this);
  206. this._onShortcutToggleScreenshare = this._onShortcutToggleScreenshare.bind(this);
  207. this._onShortcutToggleVideoQuality = this._onShortcutToggleVideoQuality.bind(this);
  208. this._onToolbarOpenFeedback = this._onToolbarOpenFeedback.bind(this);
  209. this._onToolbarOpenInvite = this._onToolbarOpenInvite.bind(this);
  210. this._onToolbarOpenKeyboardShortcuts = this._onToolbarOpenKeyboardShortcuts.bind(this);
  211. this._onToolbarOpenSpeakerStats = this._onToolbarOpenSpeakerStats.bind(this);
  212. this._onToolbarOpenVideoQuality = this._onToolbarOpenVideoQuality.bind(this);
  213. this._onToolbarToggleChat = this._onToolbarToggleChat.bind(this);
  214. this._onToolbarToggleFullScreen = this._onToolbarToggleFullScreen.bind(this);
  215. this._onToolbarToggleProfile = this._onToolbarToggleProfile.bind(this);
  216. this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
  217. this._onToolbarToggleScreenshare = this._onToolbarToggleScreenshare.bind(this);
  218. this._onToolbarToggleSharedVideo = this._onToolbarToggleSharedVideo.bind(this);
  219. this._onToolbarOpenLocalRecordingInfoDialog = this._onToolbarOpenLocalRecordingInfoDialog.bind(this);
  220. this._onShortcutToggleTileView = this._onShortcutToggleTileView.bind(this);
  221. this.state = {
  222. windowWidth: window.innerWidth
  223. };
  224. }
  225. /**
  226. * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
  227. *
  228. * @inheritdoc
  229. * @returns {void}
  230. */
  231. componentDidMount() {
  232. const KEYBOARD_SHORTCUTS = [
  233. this._shouldShowButton('videoquality') && {
  234. character: 'A',
  235. exec: this._onShortcutToggleVideoQuality,
  236. helpDescription: 'keyboardShortcuts.videoQuality'
  237. },
  238. this._shouldShowButton('chat') && {
  239. character: 'C',
  240. exec: this._onShortcutToggleChat,
  241. helpDescription: 'keyboardShortcuts.toggleChat'
  242. },
  243. this._shouldShowButton('desktop') && {
  244. character: 'D',
  245. exec: this._onShortcutToggleScreenshare,
  246. helpDescription: 'keyboardShortcuts.toggleScreensharing'
  247. },
  248. this._shouldShowButton('raisehand') && {
  249. character: 'R',
  250. exec: this._onShortcutToggleRaiseHand,
  251. helpDescription: 'keyboardShortcuts.raiseHand'
  252. },
  253. this._shouldShowButton('fullscreen') && {
  254. character: 'S',
  255. exec: this._onShortcutToggleFullScreen,
  256. helpDescription: 'keyboardShortcuts.fullScreen'
  257. },
  258. this._shouldShowButton('tileview') && {
  259. character: 'W',
  260. exec: this._onShortcutToggleTileView,
  261. helpDescription: 'toolbar.tileViewToggle'
  262. }
  263. ];
  264. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  265. if (typeof shortcut === 'object') {
  266. APP.keyboardshortcut.registerShortcut(
  267. shortcut.character,
  268. null,
  269. shortcut.exec,
  270. shortcut.helpDescription);
  271. }
  272. });
  273. window.addEventListener('resize', this._onResize);
  274. }
  275. /**
  276. * Update the visibility of the {@code OverflowMenuButton}.
  277. *
  278. * @inheritdoc
  279. */
  280. componentDidUpdate(prevProps) {
  281. // Ensure the dialog is closed when the toolbox becomes hidden.
  282. if (prevProps._overflowMenuVisible && !this.props._visible) {
  283. this._onSetOverflowVisible(false);
  284. }
  285. if (prevProps._overflowMenuVisible
  286. && !prevProps._dialog
  287. && this.props._dialog) {
  288. this._onSetOverflowVisible(false);
  289. this.props.dispatch(setToolbarHovered(false));
  290. }
  291. }
  292. /**
  293. * Removes keyboard shortcuts registered by this component.
  294. *
  295. * @inheritdoc
  296. * @returns {void}
  297. */
  298. componentWillUnmount() {
  299. [ 'A', 'C', 'D', 'R', 'S' ].forEach(letter =>
  300. APP.keyboardshortcut.unregisterShortcut(letter));
  301. window.removeEventListener('resize', this._onResize);
  302. }
  303. /**
  304. * Implements React's {@link Component#render()}.
  305. *
  306. * @inheritdoc
  307. * @returns {ReactElement}
  308. */
  309. render() {
  310. const { _visible, _visibleButtons } = this.props;
  311. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  312. _visibleButtons.size ? '' : 'no-buttons'}`;
  313. return (
  314. <div
  315. className = { rootClassNames }
  316. id = 'new-toolbox'
  317. onMouseOut = { this._onMouseOut }
  318. onMouseOver = { this._onMouseOver }>
  319. <div className = 'toolbox-background' />
  320. { this._renderToolboxContent() }
  321. </div>
  322. );
  323. }
  324. /**
  325. * Callback invoked to display {@code FeedbackDialog}.
  326. *
  327. * @private
  328. * @returns {void}
  329. */
  330. _doOpenFeedback() {
  331. const { _conference } = this.props;
  332. this.props.dispatch(openFeedbackDialog(_conference));
  333. }
  334. /**
  335. * Dispatches an action to display {@code KeyboardShortcuts}.
  336. *
  337. * @private
  338. * @returns {void}
  339. */
  340. _doOpenKeyboardShorcuts() {
  341. this.props.dispatch(openKeyboardShortcutsDialog());
  342. }
  343. /**
  344. * Callback invoked to display {@code SpeakerStats}.
  345. *
  346. * @private
  347. * @returns {void}
  348. */
  349. _doOpenSpeakerStats() {
  350. this.props.dispatch(openDialog(SpeakerStats, {
  351. conference: this.props._conference
  352. }));
  353. }
  354. /**
  355. * Dispatches an action to open the video quality dialog.
  356. *
  357. * @private
  358. * @returns {void}
  359. */
  360. _doOpenVideoQuality() {
  361. this.props.dispatch(openDialog(VideoQualityDialog));
  362. }
  363. /**
  364. * Dispatches an action to toggle the display of chat.
  365. *
  366. * @private
  367. * @returns {void}
  368. */
  369. _doToggleChat() {
  370. this.props.dispatch(toggleChat());
  371. }
  372. /**
  373. * Dispatches an action to toggle screensharing.
  374. *
  375. * @private
  376. * @returns {void}
  377. */
  378. _doToggleFullScreen() {
  379. const fullScreen = !this.props._fullScreen;
  380. this.props.dispatch(setFullScreen(fullScreen));
  381. }
  382. /**
  383. * Dispatches an action to show or hide the profile edit panel.
  384. *
  385. * @private
  386. * @returns {void}
  387. */
  388. _doToggleProfile() {
  389. this.props.dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
  390. }
  391. /**
  392. * Dispatches an action to toggle the local participant's raised hand state.
  393. *
  394. * @private
  395. * @returns {void}
  396. */
  397. _doToggleRaiseHand() {
  398. const { _localParticipantID, _raisedHand } = this.props;
  399. this.props.dispatch(participantUpdated({
  400. // XXX Only the local participant is allowed to update without
  401. // stating the JitsiConference instance (i.e. participant property
  402. // `conference` for a remote participant) because the local
  403. // participant is uniquely identified by the very fact that there is
  404. // only one local participant.
  405. id: _localParticipantID,
  406. local: true,
  407. raisedHand: !_raisedHand
  408. }));
  409. }
  410. /**
  411. * Dispatches an action to toggle screensharing.
  412. *
  413. * @private
  414. * @returns {void}
  415. */
  416. _doToggleScreenshare() {
  417. if (this.props._desktopSharingEnabled) {
  418. this.props.dispatch(toggleScreensharing());
  419. }
  420. }
  421. /**
  422. * Dispatches an action to toggle YouTube video sharing.
  423. *
  424. * @private
  425. * @returns {void}
  426. */
  427. _doToggleSharedVideo() {
  428. this.props.dispatch(toggleSharedVideo());
  429. }
  430. /**
  431. * Dispatches an action to toggle the video quality dialog.
  432. *
  433. * @private
  434. * @returns {void}
  435. */
  436. _doToggleVideoQuality() {
  437. this.props.dispatch(toggleDialog(VideoQualityDialog));
  438. }
  439. /**
  440. * Dispaches an action to toggle tile view.
  441. *
  442. * @private
  443. * @returns {void}
  444. */
  445. _doToggleTileView() {
  446. this.props.dispatch(toggleTileView());
  447. }
  448. _onMouseOut: () => void;
  449. /**
  450. * Dispatches an action signaling the toolbar is not being hovered.
  451. *
  452. * @private
  453. * @returns {void}
  454. */
  455. _onMouseOut() {
  456. this.props.dispatch(setToolbarHovered(false));
  457. }
  458. _onMouseOver: () => void;
  459. /**
  460. * Dispatches an action signaling the toolbar is being hovered.
  461. *
  462. * @private
  463. * @returns {void}
  464. */
  465. _onMouseOver() {
  466. this.props.dispatch(setToolbarHovered(true));
  467. }
  468. _onResize: () => void;
  469. /**
  470. * A window resize handler used to calculate the number of buttons we can
  471. * fit in the toolbar.
  472. *
  473. * @private
  474. * @returns {void}
  475. */
  476. _onResize() {
  477. const width = window.innerWidth;
  478. if (this.state.windowWidth !== width) {
  479. this.setState({ windowWidth: width });
  480. }
  481. }
  482. _onSetOverflowVisible: (boolean) => void;
  483. /**
  484. * Sets the visibility of the overflow menu.
  485. *
  486. * @param {boolean} visible - Whether or not the overflow menu should be
  487. * displayed.
  488. * @private
  489. * @returns {void}
  490. */
  491. _onSetOverflowVisible(visible) {
  492. this.props.dispatch(setOverflowMenuVisible(visible));
  493. }
  494. _onShortcutToggleChat: () => void;
  495. /**
  496. * Creates an analytics keyboard shortcut event and dispatches an action for
  497. * toggling the display of chat.
  498. *
  499. * @private
  500. * @returns {void}
  501. */
  502. _onShortcutToggleChat() {
  503. sendAnalytics(createShortcutEvent(
  504. 'toggle.chat',
  505. {
  506. enable: !this.props._chatOpen
  507. }));
  508. this._doToggleChat();
  509. }
  510. _onShortcutToggleVideoQuality: () => void;
  511. /**
  512. * Creates an analytics keyboard shortcut event and dispatches an action for
  513. * toggling the display of Video Quality.
  514. *
  515. * @private
  516. * @returns {void}
  517. */
  518. _onShortcutToggleVideoQuality() {
  519. sendAnalytics(createShortcutEvent('video.quality'));
  520. this._doToggleVideoQuality();
  521. }
  522. _onShortcutToggleTileView: () => void;
  523. /**
  524. * Dispatches an action for toggling the tile view.
  525. *
  526. * @private
  527. * @returns {void}
  528. */
  529. _onShortcutToggleTileView() {
  530. sendAnalytics(createShortcutEvent(
  531. 'toggle.tileview',
  532. {
  533. enable: !this.props._tileViewEnabled
  534. }));
  535. this._doToggleTileView();
  536. }
  537. _onShortcutToggleFullScreen: () => void;
  538. /**
  539. * Creates an analytics keyboard shortcut event and dispatches an action for
  540. * toggling full screen mode.
  541. *
  542. * @private
  543. * @returns {void}
  544. */
  545. _onShortcutToggleFullScreen() {
  546. sendAnalytics(createShortcutEvent(
  547. 'toggle.fullscreen',
  548. {
  549. enable: !this.props._fullScreen
  550. }));
  551. this._doToggleFullScreen();
  552. }
  553. _onShortcutToggleRaiseHand: () => void;
  554. /**
  555. * Creates an analytics keyboard shortcut event and dispatches an action for
  556. * toggling raise hand.
  557. *
  558. * @private
  559. * @returns {void}
  560. */
  561. _onShortcutToggleRaiseHand() {
  562. sendAnalytics(createShortcutEvent(
  563. 'toggle.raise.hand',
  564. ACTION_SHORTCUT_TRIGGERED,
  565. { enable: !this.props._raisedHand }));
  566. this._doToggleRaiseHand();
  567. }
  568. _onShortcutToggleScreenshare: () => void;
  569. /**
  570. * Creates an analytics keyboard shortcut event and dispatches an action for
  571. * toggling screensharing.
  572. *
  573. * @private
  574. * @returns {void}
  575. */
  576. _onShortcutToggleScreenshare() {
  577. sendAnalytics(createToolbarEvent(
  578. 'screen.sharing',
  579. {
  580. enable: !this.props._screensharing
  581. }));
  582. this._doToggleScreenshare();
  583. }
  584. _onToolbarOpenFeedback: () => void;
  585. /**
  586. * Creates an analytics toolbar event and dispatches an action for toggling
  587. * display of feedback.
  588. *
  589. * @private
  590. * @returns {void}
  591. */
  592. _onToolbarOpenFeedback() {
  593. sendAnalytics(createToolbarEvent('feedback'));
  594. this._doOpenFeedback();
  595. }
  596. _onToolbarOpenInvite: () => void;
  597. /**
  598. * Creates an analytics toolbar event and dispatches an action for opening
  599. * the modal for inviting people directly into the conference.
  600. *
  601. * @private
  602. * @returns {void}
  603. */
  604. _onToolbarOpenInvite() {
  605. sendAnalytics(createToolbarEvent('invite'));
  606. this.props.dispatch(beginAddPeople());
  607. }
  608. _onToolbarOpenKeyboardShortcuts: () => void;
  609. /**
  610. * Creates an analytics toolbar event and dispatches an action for opening
  611. * the modal for showing available keyboard shortcuts.
  612. *
  613. * @private
  614. * @returns {void}
  615. */
  616. _onToolbarOpenKeyboardShortcuts() {
  617. sendAnalytics(createToolbarEvent('shortcuts'));
  618. this._doOpenKeyboardShorcuts();
  619. }
  620. _onToolbarOpenSpeakerStats: () => void;
  621. /**
  622. * Creates an analytics toolbar event and dispatches an action for opening
  623. * the speaker stats modal.
  624. *
  625. * @private
  626. * @returns {void}
  627. */
  628. _onToolbarOpenSpeakerStats() {
  629. sendAnalytics(createToolbarEvent('speaker.stats'));
  630. this._doOpenSpeakerStats();
  631. }
  632. _onToolbarOpenVideoQuality: () => void;
  633. /**
  634. * Creates an analytics toolbar event and dispatches an action for toggling
  635. * open the video quality dialog.
  636. *
  637. * @private
  638. * @returns {void}
  639. */
  640. _onToolbarOpenVideoQuality() {
  641. sendAnalytics(createToolbarEvent('video.quality'));
  642. this._doOpenVideoQuality();
  643. }
  644. _onToolbarToggleChat: () => void;
  645. /**
  646. * Creates an analytics toolbar event and dispatches an action for toggling
  647. * the display of chat.
  648. *
  649. * @private
  650. * @returns {void}
  651. */
  652. _onToolbarToggleChat() {
  653. sendAnalytics(createToolbarEvent(
  654. 'toggle.chat',
  655. {
  656. enable: !this.props._chatOpen
  657. }));
  658. this._doToggleChat();
  659. }
  660. _onToolbarToggleFullScreen: () => void;
  661. /**
  662. * Creates an analytics toolbar event and dispatches an action for toggling
  663. * full screen mode.
  664. *
  665. * @private
  666. * @returns {void}
  667. */
  668. _onToolbarToggleFullScreen() {
  669. sendAnalytics(createToolbarEvent(
  670. 'toggle.fullscreen',
  671. {
  672. enable: !this.props._fullScreen
  673. }));
  674. this._doToggleFullScreen();
  675. }
  676. _onToolbarToggleProfile: () => void;
  677. /**
  678. * Creates an analytics toolbar event and dispatches an action for showing
  679. * or hiding the profile edit panel.
  680. *
  681. * @private
  682. * @returns {void}
  683. */
  684. _onToolbarToggleProfile() {
  685. sendAnalytics(createToolbarEvent('profile'));
  686. this._doToggleProfile();
  687. }
  688. _onToolbarToggleRaiseHand: () => void;
  689. /**
  690. * Creates an analytics toolbar event and dispatches an action for toggling
  691. * raise hand.
  692. *
  693. * @private
  694. * @returns {void}
  695. */
  696. _onToolbarToggleRaiseHand() {
  697. sendAnalytics(createToolbarEvent(
  698. 'raise.hand',
  699. { enable: !this.props._raisedHand }));
  700. this._doToggleRaiseHand();
  701. }
  702. _onToolbarToggleScreenshare: () => void;
  703. /**
  704. * Creates an analytics toolbar event and dispatches an action for toggling
  705. * screensharing.
  706. *
  707. * @private
  708. * @returns {void}
  709. */
  710. _onToolbarToggleScreenshare() {
  711. if (!this.props._desktopSharingEnabled) {
  712. return;
  713. }
  714. sendAnalytics(createShortcutEvent(
  715. 'toggle.screen.sharing',
  716. ACTION_SHORTCUT_TRIGGERED,
  717. { enable: !this.props._screensharing }));
  718. this._doToggleScreenshare();
  719. }
  720. _onToolbarToggleSharedVideo: () => void;
  721. /**
  722. * Creates an analytics toolbar event and dispatches an action for toggling
  723. * the sharing of a YouTube video.
  724. *
  725. * @private
  726. * @returns {void}
  727. */
  728. _onToolbarToggleSharedVideo() {
  729. sendAnalytics(createToolbarEvent('shared.video.toggled',
  730. {
  731. enable: !this.props._sharingVideo
  732. }));
  733. this._doToggleSharedVideo();
  734. }
  735. _onToolbarOpenLocalRecordingInfoDialog: () => void;
  736. /**
  737. * Opens the {@code LocalRecordingInfoDialog}.
  738. *
  739. * @private
  740. * @returns {void}
  741. */
  742. _onToolbarOpenLocalRecordingInfoDialog() {
  743. sendAnalytics(createToolbarEvent('local.recording'));
  744. this.props.dispatch(openDialog(LocalRecordingInfoDialog));
  745. }
  746. /**
  747. * Returns true if the the desktop sharing button should be visible and
  748. * false otherwise.
  749. *
  750. * @returns {boolean}
  751. */
  752. _isDesktopSharingButtonVisible() {
  753. const {
  754. _desktopSharingEnabled,
  755. _desktopSharingDisabledTooltipKey
  756. } = this.props;
  757. return _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  758. }
  759. /**
  760. * Renders a button for toggleing screen sharing.
  761. *
  762. * @private
  763. * @param {boolean} isInOverflowMenu - True if the button is moved to the
  764. * overflow menu.
  765. * @returns {ReactElement|null}
  766. */
  767. _renderDesktopSharingButton(isInOverflowMenu = false) {
  768. const {
  769. _desktopSharingEnabled,
  770. _desktopSharingDisabledTooltipKey,
  771. _screensharing,
  772. t
  773. } = this.props;
  774. if (!this._isDesktopSharingButtonVisible()) {
  775. return null;
  776. }
  777. if (isInOverflowMenu) {
  778. return (
  779. <OverflowMenuItem
  780. accessibilityLabel
  781. = { t('toolbar.accessibilityLabel.shareYourScreen') }
  782. disabled = { _desktopSharingEnabled }
  783. icon = { IconShareDesktop }
  784. iconId = 'share-desktop'
  785. key = 'desktop'
  786. onClick = { this._onToolbarToggleScreenshare }
  787. text = {
  788. t(`toolbar.${
  789. _screensharing
  790. ? 'stopScreenSharing' : 'startScreenSharing'}`
  791. )
  792. } />
  793. );
  794. }
  795. const tooltip = t(
  796. _desktopSharingEnabled
  797. ? 'dialog.shareYourScreen' : _desktopSharingDisabledTooltipKey);
  798. return (
  799. <ToolbarButton
  800. accessibilityLabel
  801. = { t('toolbar.accessibilityLabel.shareYourScreen') }
  802. disabled = { !_desktopSharingEnabled }
  803. icon = { IconShareDesktop }
  804. onClick = { this._onToolbarToggleScreenshare }
  805. toggled = { _screensharing }
  806. tooltip = { tooltip } />
  807. );
  808. }
  809. /**
  810. * Returns true if the profile button is visible and false otherwise.
  811. *
  812. * @returns {boolean}
  813. */
  814. _isProfileVisible() {
  815. return this.props._isGuest && this._shouldShowButton('profile');
  816. }
  817. /**
  818. * Renders the list elements of the overflow menu.
  819. *
  820. * @private
  821. * @returns {Array<ReactElement>}
  822. */
  823. _renderOverflowMenuContent() {
  824. const {
  825. _feedbackConfigured,
  826. _fullScreen,
  827. _screensharing,
  828. _sharingVideo,
  829. t
  830. } = this.props;
  831. return [
  832. this._isProfileVisible()
  833. && <OverflowMenuProfileItem
  834. key = 'profile'
  835. onClick = { this._onToolbarToggleProfile } />,
  836. this._shouldShowButton('videoquality')
  837. && <OverflowMenuVideoQualityItem
  838. key = 'videoquality'
  839. onClick = { this._onToolbarOpenVideoQuality } />,
  840. this._shouldShowButton('fullscreen')
  841. && <OverflowMenuItem
  842. accessibilityLabel = { t('toolbar.accessibilityLabel.fullScreen') }
  843. icon = { _fullScreen ? IconExitFullScreen : IconFullScreen }
  844. key = 'fullscreen'
  845. onClick = { this._onToolbarToggleFullScreen }
  846. text = { _fullScreen ? t('toolbar.exitFullScreen') : t('toolbar.enterFullScreen') } />,
  847. <LiveStreamButton
  848. key = 'livestreaming'
  849. showLabel = { true } />,
  850. <RecordButton
  851. key = 'record'
  852. showLabel = { true } />,
  853. this._shouldShowButton('sharedvideo')
  854. && <OverflowMenuItem
  855. accessibilityLabel = { t('toolbar.accessibilityLabel.sharedvideo') }
  856. icon = { IconShareVideo }
  857. key = 'sharedvideo'
  858. onClick = { this._onToolbarToggleSharedVideo }
  859. text = { _sharingVideo ? t('toolbar.stopSharedVideo') : t('toolbar.sharedvideo') } />,
  860. this._shouldShowButton('etherpad')
  861. && <SharedDocumentButton
  862. key = 'etherpad'
  863. showLabel = { true } />,
  864. <VideoBlurButton
  865. key = 'videobackgroundblur'
  866. showLabel = { true }
  867. visible = { this._shouldShowButton('videobackgroundblur') && !_screensharing } />,
  868. <SettingsButton
  869. key = 'settings'
  870. showLabel = { true }
  871. visible = { this._shouldShowButton('settings') } />,
  872. this._shouldShowButton('stats')
  873. && <OverflowMenuItem
  874. accessibilityLabel = { t('toolbar.accessibilityLabel.speakerStats') }
  875. icon = { IconPresentation }
  876. key = 'stats'
  877. onClick = { this._onToolbarOpenSpeakerStats }
  878. text = { t('toolbar.speakerStats') } />,
  879. this._shouldShowButton('feedback')
  880. && _feedbackConfigured
  881. && <OverflowMenuItem
  882. accessibilityLabel = { t('toolbar.accessibilityLabel.feedback') }
  883. icon = { IconFeedback }
  884. key = 'feedback'
  885. onClick = { this._onToolbarOpenFeedback }
  886. text = { t('toolbar.feedback') } />,
  887. this._shouldShowButton('shortcuts')
  888. && <OverflowMenuItem
  889. accessibilityLabel = { t('toolbar.accessibilityLabel.shortcuts') }
  890. icon = { IconOpenInNew }
  891. key = 'shortcuts'
  892. onClick = { this._onToolbarOpenKeyboardShortcuts }
  893. text = { t('toolbar.shortcuts') } />,
  894. this._shouldShowButton('download')
  895. && <DownloadButton
  896. key = 'download'
  897. showLabel = { true } />,
  898. this._shouldShowButton('help')
  899. && <HelpButton
  900. key = 'help'
  901. showLabel = { true } />
  902. ];
  903. }
  904. /**
  905. * Renders a list of buttons that are moved to the overflow menu.
  906. *
  907. * @private
  908. * @param {Array<string>} movedButtons - The names of the buttons to be
  909. * moved.
  910. * @returns {Array<ReactElement>}
  911. */
  912. _renderMovedButtons(movedButtons) {
  913. const {
  914. _chatOpen,
  915. _raisedHand,
  916. t
  917. } = this.props;
  918. return movedButtons.map(buttonName => {
  919. switch (buttonName) {
  920. case 'desktop':
  921. return this._renderDesktopSharingButton(true);
  922. case 'raisehand':
  923. return (
  924. <OverflowMenuItem
  925. accessibilityLabel =
  926. { t('toolbar.accessibilityLabel.raiseHand') }
  927. icon = { IconRaisedHand }
  928. key = 'raisedHand'
  929. onClick = { this._onToolbarToggleRaiseHand }
  930. text = {
  931. t(`toolbar.${
  932. _raisedHand
  933. ? 'lowerYourHand' : 'raiseYourHand'}`
  934. )
  935. } />
  936. );
  937. case 'chat':
  938. return (
  939. <OverflowMenuItem
  940. accessibilityLabel =
  941. { t('toolbar.accessibilityLabel.chat') }
  942. icon = { IconChat }
  943. key = 'chat'
  944. onClick = { this._onToolbarToggleChat }
  945. text = {
  946. t(`toolbar.${
  947. _chatOpen ? 'closeChat' : 'openChat'}`
  948. )
  949. } />
  950. );
  951. case 'closedcaptions':
  952. return <ClosedCaptionButton showLabel = { true } />;
  953. case 'info':
  954. return <InfoDialogButton showLabel = { true } />;
  955. case 'invite':
  956. return (
  957. <OverflowMenuItem
  958. accessibilityLabel = { t('toolbar.accessibilityLabel.invite') }
  959. icon = { IconInvite }
  960. key = 'invite'
  961. onClick = { this._onToolbarOpenInvite }
  962. text = { t('toolbar.invite') } />
  963. );
  964. case 'tileview':
  965. return <TileViewButton showLabel = { true } />;
  966. case 'localrecording':
  967. return (
  968. <OverflowMenuItem
  969. accessibilityLabel = { t('toolbar.accessibilityLabel.localRecording') }
  970. icon = { IconRec }
  971. key = 'localrecording'
  972. onClick = { this._onToolbarOpenLocalRecordingInfoDialog }
  973. text = { t('localRecording.dialogTitle') } />
  974. );
  975. default:
  976. return null;
  977. }
  978. });
  979. }
  980. /**
  981. * Renders the toolbox content.
  982. *
  983. * @returns {Array<ReactElement>}
  984. */
  985. _renderToolboxContent() {
  986. const {
  987. _chatOpen,
  988. _hideInviteButton,
  989. _overflowMenuVisible,
  990. _raisedHand,
  991. t
  992. } = this.props;
  993. const overflowMenuContent = this._renderOverflowMenuContent();
  994. const overflowHasItems = Boolean(overflowMenuContent.filter(child => child).length);
  995. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  996. const buttonsLeft = [];
  997. const buttonsRight = [];
  998. const maxNumberOfButtonsPerGroup = Math.floor(
  999. (
  1000. this.state.windowWidth
  1001. - 168 // the width of the central group by design
  1002. - 48 // the minimum space between the button groups
  1003. )
  1004. / 56 // the width + padding of a button
  1005. / 2 // divide by the number of groups(left and right group)
  1006. );
  1007. if (this._shouldShowButton('desktop')
  1008. && this._isDesktopSharingButtonVisible()) {
  1009. buttonsLeft.push('desktop');
  1010. }
  1011. if (this._shouldShowButton('raisehand')) {
  1012. buttonsLeft.push('raisehand');
  1013. }
  1014. if (this._shouldShowButton('chat')) {
  1015. buttonsLeft.push('chat');
  1016. }
  1017. if (this._shouldShowButton('closedcaptions')) {
  1018. buttonsLeft.push('closedcaptions');
  1019. }
  1020. if (overflowHasItems) {
  1021. buttonsRight.push('overflowmenu');
  1022. }
  1023. if (this._shouldShowButton('info')) {
  1024. buttonsRight.push('info');
  1025. }
  1026. if (this._shouldShowButton('invite') && !_hideInviteButton) {
  1027. buttonsRight.push('invite');
  1028. }
  1029. if (this._shouldShowButton('tileview')) {
  1030. buttonsRight.push('tileview');
  1031. }
  1032. if (this._shouldShowButton('localrecording')) {
  1033. buttonsRight.push('localrecording');
  1034. }
  1035. const movedButtons = [];
  1036. if (buttonsLeft.length > maxNumberOfButtonsPerGroup) {
  1037. movedButtons.push(...buttonsLeft.splice(
  1038. maxNumberOfButtonsPerGroup,
  1039. buttonsLeft.length - maxNumberOfButtonsPerGroup));
  1040. if (buttonsRight.indexOf('overflowmenu') === -1) {
  1041. buttonsRight.unshift('overflowmenu');
  1042. }
  1043. }
  1044. if (buttonsRight.length > maxNumberOfButtonsPerGroup) {
  1045. if (buttonsRight.indexOf('overflowmenu') === -1) {
  1046. buttonsRight.unshift('overflowmenu');
  1047. }
  1048. let numberOfButtons = maxNumberOfButtonsPerGroup;
  1049. // make sure the more button will be displayed when we move buttons.
  1050. if (numberOfButtons === 0) {
  1051. numberOfButtons++;
  1052. }
  1053. movedButtons.push(...buttonsRight.splice(
  1054. numberOfButtons,
  1055. buttonsRight.length - numberOfButtons));
  1056. }
  1057. overflowMenuContent.splice(
  1058. 1, 0, ...this._renderMovedButtons(movedButtons));
  1059. return (
  1060. <div className = 'toolbox-content'>
  1061. <div className = 'button-group-left'>
  1062. { buttonsLeft.indexOf('desktop') !== -1
  1063. && this._renderDesktopSharingButton() }
  1064. { buttonsLeft.indexOf('raisehand') !== -1
  1065. && <ToolbarButton
  1066. accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
  1067. icon = { IconRaisedHand }
  1068. onClick = { this._onToolbarToggleRaiseHand }
  1069. toggled = { _raisedHand }
  1070. tooltip = { t('toolbar.raiseHand') } /> }
  1071. { buttonsLeft.indexOf('chat') !== -1
  1072. && <div className = 'toolbar-button-with-badge'>
  1073. <ToolbarButton
  1074. accessibilityLabel = { t('toolbar.accessibilityLabel.chat') }
  1075. icon = { IconChat }
  1076. onClick = { this._onToolbarToggleChat }
  1077. toggled = { _chatOpen }
  1078. tooltip = { t('toolbar.chat') } />
  1079. <ChatCounter />
  1080. </div> }
  1081. {
  1082. buttonsLeft.indexOf('closedcaptions') !== -1
  1083. && <ClosedCaptionButton />
  1084. }
  1085. </div>
  1086. <div className = 'button-group-center'>
  1087. <AudioMuteButton
  1088. visible = { this._shouldShowButton('microphone') } />
  1089. <HangupButton
  1090. visible = { this._shouldShowButton('hangup') } />
  1091. <VideoMuteButton
  1092. visible = { this._shouldShowButton('camera') } />
  1093. </div>
  1094. <div className = 'button-group-right'>
  1095. { buttonsRight.indexOf('localrecording') !== -1
  1096. && <LocalRecordingButton
  1097. onClick = {
  1098. this._onToolbarOpenLocalRecordingInfoDialog
  1099. } />
  1100. }
  1101. { buttonsRight.indexOf('tileview') !== -1
  1102. && <TileViewButton /> }
  1103. { buttonsRight.indexOf('invite') !== -1
  1104. && <ToolbarButton
  1105. accessibilityLabel =
  1106. { t('toolbar.accessibilityLabel.invite') }
  1107. icon = { IconInvite }
  1108. onClick = { this._onToolbarOpenInvite }
  1109. tooltip = { t('toolbar.invite') } /> }
  1110. {
  1111. buttonsRight.indexOf('info') !== -1
  1112. && <InfoDialogButton />
  1113. }
  1114. { buttonsRight.indexOf('overflowmenu') !== -1
  1115. && <OverflowMenuButton
  1116. isOpen = { _overflowMenuVisible }
  1117. onVisibilityChange = { this._onSetOverflowVisible }>
  1118. <ul
  1119. aria-label = { t(toolbarAccLabel) }
  1120. className = 'overflow-menu'>
  1121. { overflowMenuContent }
  1122. </ul>
  1123. </OverflowMenuButton> }
  1124. </div>
  1125. </div>);
  1126. }
  1127. _shouldShowButton: (string) => boolean;
  1128. /**
  1129. * Returns if a button name has been explicitly configured to be displayed.
  1130. *
  1131. * @param {string} buttonName - The name of the button, as expected in
  1132. * {@link interfaceConfig}.
  1133. * @private
  1134. * @returns {boolean} True if the button should be displayed.
  1135. */
  1136. _shouldShowButton(buttonName) {
  1137. return this.props._visibleButtons.has(buttonName);
  1138. }
  1139. }
  1140. /**
  1141. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  1142. * props.
  1143. *
  1144. * @param {Object} state - The redux store/state.
  1145. * @private
  1146. * @returns {{}}
  1147. */
  1148. function _mapStateToProps(state) {
  1149. const { conference } = state['features/base/conference'];
  1150. let { desktopSharingEnabled } = state['features/base/conference'];
  1151. const {
  1152. callStatsID,
  1153. iAmRecorder
  1154. } = state['features/base/config'];
  1155. const sharedVideoStatus = state['features/shared-video'].status;
  1156. const {
  1157. fullScreen,
  1158. overflowMenuVisible
  1159. } = state['features/toolbox'];
  1160. const localParticipant = getLocalParticipant(state);
  1161. const localRecordingStates = state['features/local-recording'];
  1162. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  1163. const addPeopleEnabled = isAddPeopleEnabled(state);
  1164. const dialOutEnabled = isDialOutEnabled(state);
  1165. let desktopSharingDisabledTooltipKey;
  1166. if (state['features/base/config'].enableFeaturesBasedOnToken) {
  1167. // we enable desktop sharing if any participant already have this
  1168. // feature enabled
  1169. desktopSharingEnabled = getParticipants(state)
  1170. .find(({ features = {} }) =>
  1171. String(features['screen-sharing']) === 'true') !== undefined;
  1172. // we want to show button and tooltip
  1173. if (state['features/base/jwt'].isGuest) {
  1174. desktopSharingDisabledTooltipKey
  1175. = 'dialog.shareYourScreenDisabledForGuest';
  1176. } else {
  1177. desktopSharingDisabledTooltipKey
  1178. = 'dialog.shareYourScreenDisabled';
  1179. }
  1180. }
  1181. // NB: We compute the buttons again here because if URL parameters were used to
  1182. // override them we'd miss it.
  1183. const buttons = new Set(interfaceConfig.TOOLBAR_BUTTONS);
  1184. return {
  1185. _chatOpen: state['features/chat'].isOpen,
  1186. _conference: conference,
  1187. _desktopSharingEnabled: desktopSharingEnabled,
  1188. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  1189. _dialog: Boolean(state['features/base/dialog'].component),
  1190. _feedbackConfigured: Boolean(callStatsID),
  1191. _hideInviteButton:
  1192. iAmRecorder || (!addPeopleEnabled && !dialOutEnabled),
  1193. _isGuest: state['features/base/jwt'].isGuest,
  1194. _fullScreen: fullScreen,
  1195. _tileViewEnabled: state['features/video-layout'].tileViewEnabled,
  1196. _localParticipantID: localParticipant.id,
  1197. _localRecState: localRecordingStates,
  1198. _overflowMenuVisible: overflowMenuVisible,
  1199. _raisedHand: localParticipant.raisedHand,
  1200. _screensharing: localVideo && localVideo.videoType === 'desktop',
  1201. _sharingVideo: sharedVideoStatus === 'playing'
  1202. || sharedVideoStatus === 'start'
  1203. || sharedVideoStatus === 'pause',
  1204. _visible: isToolboxVisible(state),
  1205. _visibleButtons: equals(visibleButtons, buttons) ? visibleButtons : buttons
  1206. };
  1207. }
  1208. export default translate(connect(_mapStateToProps)(Toolbox));