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

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