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

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