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

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