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

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