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

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