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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  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 { getLocalVideoTrack, toggleScreensharing } from '../../../base/tracks';
  18. import { ChatCounter, toggleChat } from '../../../chat';
  19. import { toggleDocument } from '../../../etherpad';
  20. import { openFeedbackDialog } from '../../../feedback';
  21. import {
  22. beginAddPeople,
  23. InfoDialogButton,
  24. isAddPeopleEnabled,
  25. isDialOutEnabled
  26. } from '../../../invite';
  27. import { openKeyboardShortcutsDialog } from '../../../keyboard-shortcuts';
  28. import {
  29. LocalRecordingButton,
  30. LocalRecordingInfoDialog
  31. } from '../../../local-recording';
  32. import {
  33. LiveStreamButton,
  34. RecordButton
  35. } from '../../../recording';
  36. import {
  37. SETTINGS_TABS,
  38. SettingsButton,
  39. openSettingsDialog
  40. } from '../../../settings';
  41. import { toggleSharedVideo } from '../../../shared-video';
  42. import { SpeakerStats } from '../../../speaker-stats';
  43. import { TileViewButton } from '../../../video-layout';
  44. import {
  45. OverflowMenuVideoQualityItem,
  46. VideoQualityDialog
  47. } from '../../../video-quality';
  48. import {
  49. setFullScreen,
  50. setOverflowMenuVisible,
  51. setToolbarHovered
  52. } from '../../actions';
  53. import AudioMuteButton from '../AudioMuteButton';
  54. import HangupButton from '../HangupButton';
  55. import OverflowMenuButton from './OverflowMenuButton';
  56. import OverflowMenuItem from './OverflowMenuItem';
  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. declare var APP: Object;
  155. declare var interfaceConfig: Object;
  156. /**
  157. * Implements the conference toolbox on React/Web.
  158. *
  159. * @extends Component
  160. */
  161. class Toolbox extends Component<Props> {
  162. /**
  163. * Initializes a new {@code Toolbox} instance.
  164. *
  165. * @param {Props} props - The read-only React {@code Component} props with
  166. * which the new instance is to be initialized.
  167. */
  168. constructor(props: Props) {
  169. super(props);
  170. // Bind event handlers so they are only bound once per instance.
  171. this._onMouseOut = this._onMouseOut.bind(this);
  172. this._onMouseOver = this._onMouseOver.bind(this);
  173. this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
  174. this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
  175. this._onShortcutToggleFullScreen
  176. = this._onShortcutToggleFullScreen.bind(this);
  177. this._onShortcutToggleRaiseHand
  178. = this._onShortcutToggleRaiseHand.bind(this);
  179. this._onShortcutToggleScreenshare
  180. = this._onShortcutToggleScreenshare.bind(this);
  181. this._onToolbarOpenFeedback
  182. = this._onToolbarOpenFeedback.bind(this);
  183. this._onToolbarOpenInvite = this._onToolbarOpenInvite.bind(this);
  184. this._onToolbarOpenKeyboardShortcuts
  185. = this._onToolbarOpenKeyboardShortcuts.bind(this);
  186. this._onToolbarOpenSpeakerStats
  187. = this._onToolbarOpenSpeakerStats.bind(this);
  188. this._onToolbarOpenVideoQuality
  189. = this._onToolbarOpenVideoQuality.bind(this);
  190. this._onToolbarToggleChat = this._onToolbarToggleChat.bind(this);
  191. this._onToolbarToggleEtherpad
  192. = this._onToolbarToggleEtherpad.bind(this);
  193. this._onToolbarToggleFullScreen
  194. = this._onToolbarToggleFullScreen.bind(this);
  195. this._onToolbarToggleProfile
  196. = this._onToolbarToggleProfile.bind(this);
  197. this._onToolbarToggleRaiseHand
  198. = this._onToolbarToggleRaiseHand.bind(this);
  199. this._onToolbarToggleScreenshare
  200. = this._onToolbarToggleScreenshare.bind(this);
  201. this._onToolbarToggleSharedVideo
  202. = this._onToolbarToggleSharedVideo.bind(this);
  203. this._onToolbarOpenLocalRecordingInfoDialog
  204. = this._onToolbarOpenLocalRecordingInfoDialog.bind(this);
  205. }
  206. /**
  207. * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
  208. *
  209. * @inheritdoc
  210. * @returns {void}
  211. */
  212. componentDidMount() {
  213. const KEYBOARD_SHORTCUTS = [
  214. this._shouldShowButton('chat') && {
  215. character: 'C',
  216. exec: this._onShortcutToggleChat,
  217. helpDescription: 'keyboardShortcuts.toggleChat'
  218. },
  219. this._shouldShowButton('desktop') && {
  220. character: 'D',
  221. exec: this._onShortcutToggleScreenshare,
  222. helpDescription: 'keyboardShortcuts.toggleScreensharing'
  223. },
  224. this._shouldShowButton('raisehand') && {
  225. character: 'R',
  226. exec: this._onShortcutToggleRaiseHand,
  227. helpDescription: 'keyboardShortcuts.raiseHand'
  228. },
  229. this._shouldShowButton('fullscreen') && {
  230. character: 'S',
  231. exec: this._onShortcutToggleFullScreen,
  232. helpDescription: 'keyboardShortcuts.fullScreen'
  233. }
  234. ];
  235. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  236. if (typeof shortcut === 'object') {
  237. APP.keyboardshortcut.registerShortcut(
  238. shortcut.character,
  239. null,
  240. shortcut.exec,
  241. shortcut.helpDescription);
  242. }
  243. });
  244. }
  245. /**
  246. * Update the visibility of the {@code OverflowMenuButton}.
  247. *
  248. * @inheritdoc
  249. */
  250. componentDidUpdate(prevProps) {
  251. // Ensure the dialog is closed when the toolbox becomes hidden.
  252. if (prevProps._overflowMenuVisible && !this.props._visible) {
  253. this._onSetOverflowVisible(false);
  254. }
  255. if (prevProps._overflowMenuVisible
  256. && !prevProps._dialog
  257. && this.props._dialog) {
  258. this._onSetOverflowVisible(false);
  259. this.props.dispatch(setToolbarHovered(false));
  260. }
  261. }
  262. /**
  263. * Removes keyboard shortcuts registered by this component.
  264. *
  265. * @inheritdoc
  266. * @returns {void}
  267. */
  268. componentWillUnmount() {
  269. [ 'C', 'D', 'R', 'S' ].forEach(letter =>
  270. APP.keyboardshortcut.unregisterShortcut(letter));
  271. }
  272. /**
  273. * Implements React's {@link Component#render()}.
  274. *
  275. * @inheritdoc
  276. * @returns {ReactElement}
  277. */
  278. render() {
  279. const { _visible, _visibleButtons } = this.props;
  280. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  281. _visibleButtons.size ? '' : 'no-buttons'}`;
  282. return (
  283. <div
  284. className = { rootClassNames }
  285. id = 'new-toolbox'
  286. onMouseOut = { this._onMouseOut }
  287. onMouseOver = { this._onMouseOver }>
  288. <div className = 'toolbox-background' />
  289. { this._renderToolboxContent() }
  290. </div>
  291. );
  292. }
  293. /**
  294. * Callback invoked to display {@code FeedbackDialog}.
  295. *
  296. * @private
  297. * @returns {void}
  298. */
  299. _doOpenFeedback() {
  300. const { _conference } = this.props;
  301. this.props.dispatch(openFeedbackDialog(_conference));
  302. }
  303. /**
  304. * Dispatches an action to display {@code KeyboardShortcuts}.
  305. *
  306. * @private
  307. * @returns {void}
  308. */
  309. _doOpenKeyboardShorcuts() {
  310. this.props.dispatch(openKeyboardShortcutsDialog());
  311. }
  312. /**
  313. * Callback invoked to display {@code SpeakerStats}.
  314. *
  315. * @private
  316. * @returns {void}
  317. */
  318. _doOpenSpeakerStats() {
  319. this.props.dispatch(openDialog(SpeakerStats, {
  320. conference: this.props._conference
  321. }));
  322. }
  323. /**
  324. * Dispatches an action to toggle the video quality dialog.
  325. *
  326. * @private
  327. * @returns {void}
  328. */
  329. _doOpenVideoQuality() {
  330. this.props.dispatch(openDialog(VideoQualityDialog));
  331. }
  332. /**
  333. * Dispatches an action to toggle the display of chat.
  334. *
  335. * @private
  336. * @returns {void}
  337. */
  338. _doToggleChat() {
  339. this.props.dispatch(toggleChat());
  340. }
  341. /**
  342. * Dispatches an action to show or hide document editing.
  343. *
  344. * @private
  345. * @returns {void}
  346. */
  347. _doToggleEtherpad() {
  348. this.props.dispatch(toggleDocument());
  349. }
  350. /**
  351. * Dispatches an action to toggle screensharing.
  352. *
  353. * @private
  354. * @returns {void}
  355. */
  356. _doToggleFullScreen() {
  357. const fullScreen = !this.props._fullScreen;
  358. this.props.dispatch(setFullScreen(fullScreen));
  359. }
  360. /**
  361. * Dispatches an action to show or hide the profile edit panel.
  362. *
  363. * @private
  364. * @returns {void}
  365. */
  366. _doToggleProfile() {
  367. this.props.dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
  368. }
  369. /**
  370. * Dispatches an action to toggle the local participant's raised hand state.
  371. *
  372. * @private
  373. * @returns {void}
  374. */
  375. _doToggleRaiseHand() {
  376. const { _localParticipantID, _raisedHand } = this.props;
  377. this.props.dispatch(participantUpdated({
  378. // XXX Only the local participant is allowed to update without
  379. // stating the JitsiConference instance (i.e. participant property
  380. // `conference` for a remote participant) because the local
  381. // participant is uniquely identified by the very fact that there is
  382. // only one local participant.
  383. id: _localParticipantID,
  384. local: true,
  385. raisedHand: !_raisedHand
  386. }));
  387. }
  388. /**
  389. * Dispatches an action to toggle screensharing.
  390. *
  391. * @private
  392. * @returns {void}
  393. */
  394. _doToggleScreenshare() {
  395. if (this.props._desktopSharingEnabled) {
  396. this.props.dispatch(toggleScreensharing());
  397. }
  398. }
  399. /**
  400. * Dispatches an action to toggle YouTube video sharing.
  401. *
  402. * @private
  403. * @returns {void}
  404. */
  405. _doToggleSharedVideo() {
  406. this.props.dispatch(toggleSharedVideo());
  407. }
  408. _onMouseOut: () => void;
  409. /**
  410. * Dispatches an action signaling the toolbar is not being hovered.
  411. *
  412. * @private
  413. * @returns {void}
  414. */
  415. _onMouseOut() {
  416. this.props.dispatch(setToolbarHovered(false));
  417. }
  418. _onMouseOver: () => void;
  419. /**
  420. * Dispatches an action signaling the toolbar is being hovered.
  421. *
  422. * @private
  423. * @returns {void}
  424. */
  425. _onMouseOver() {
  426. this.props.dispatch(setToolbarHovered(true));
  427. }
  428. _onSetOverflowVisible: (boolean) => void;
  429. /**
  430. * Sets the visibility of the overflow menu.
  431. *
  432. * @param {boolean} visible - Whether or not the overflow menu should be
  433. * displayed.
  434. * @private
  435. * @returns {void}
  436. */
  437. _onSetOverflowVisible(visible) {
  438. this.props.dispatch(setOverflowMenuVisible(visible));
  439. }
  440. _onShortcutToggleChat: () => void;
  441. /**
  442. * Creates an analytics keyboard shortcut event and dispatches an action for
  443. * toggling the display of chat.
  444. *
  445. * @private
  446. * @returns {void}
  447. */
  448. _onShortcutToggleChat() {
  449. sendAnalytics(createShortcutEvent(
  450. 'toggle.chat',
  451. {
  452. enable: !this.props._chatOpen
  453. }));
  454. this._doToggleChat();
  455. }
  456. _onShortcutToggleFullScreen: () => void;
  457. /**
  458. * Creates an analytics keyboard shortcut event and dispatches an action for
  459. * toggling full screen mode.
  460. *
  461. * @private
  462. * @returns {void}
  463. */
  464. _onShortcutToggleFullScreen() {
  465. sendAnalytics(createShortcutEvent(
  466. 'toggle.fullscreen',
  467. {
  468. enable: !this.props._fullScreen
  469. }));
  470. this._doToggleFullScreen();
  471. }
  472. _onShortcutToggleRaiseHand: () => void;
  473. /**
  474. * Creates an analytics keyboard shortcut event and dispatches an action for
  475. * toggling raise hand.
  476. *
  477. * @private
  478. * @returns {void}
  479. */
  480. _onShortcutToggleRaiseHand() {
  481. sendAnalytics(createShortcutEvent(
  482. 'toggle.raise.hand',
  483. ACTION_SHORTCUT_TRIGGERED,
  484. { enable: !this.props._raisedHand }));
  485. this._doToggleRaiseHand();
  486. }
  487. _onShortcutToggleScreenshare: () => void;
  488. /**
  489. * Creates an analytics keyboard shortcut event and dispatches an action for
  490. * toggling screensharing.
  491. *
  492. * @private
  493. * @returns {void}
  494. */
  495. _onShortcutToggleScreenshare() {
  496. sendAnalytics(createToolbarEvent(
  497. 'screen.sharing',
  498. {
  499. enable: !this.props._screensharing
  500. }));
  501. this._doToggleScreenshare();
  502. }
  503. _onToolbarOpenFeedback: () => void;
  504. /**
  505. * Creates an analytics toolbar event and dispatches an action for toggling
  506. * display of feedback.
  507. *
  508. * @private
  509. * @returns {void}
  510. */
  511. _onToolbarOpenFeedback() {
  512. sendAnalytics(createToolbarEvent('feedback'));
  513. this._doOpenFeedback();
  514. }
  515. _onToolbarOpenInvite: () => void;
  516. /**
  517. * Creates an analytics toolbar event and dispatches an action for opening
  518. * the modal for inviting people directly into the conference.
  519. *
  520. * @private
  521. * @returns {void}
  522. */
  523. _onToolbarOpenInvite() {
  524. sendAnalytics(createToolbarEvent('invite'));
  525. this.props.dispatch(beginAddPeople());
  526. }
  527. _onToolbarOpenKeyboardShortcuts: () => void;
  528. /**
  529. * Creates an analytics toolbar event and dispatches an action for opening
  530. * the modal for showing available keyboard shortcuts.
  531. *
  532. * @private
  533. * @returns {void}
  534. */
  535. _onToolbarOpenKeyboardShortcuts() {
  536. sendAnalytics(createToolbarEvent('shortcuts'));
  537. this._doOpenKeyboardShorcuts();
  538. }
  539. _onToolbarOpenSpeakerStats: () => void;
  540. /**
  541. * Creates an analytics toolbar event and dispatches an action for opening
  542. * the speaker stats modal.
  543. *
  544. * @private
  545. * @returns {void}
  546. */
  547. _onToolbarOpenSpeakerStats() {
  548. sendAnalytics(createToolbarEvent('speaker.stats'));
  549. this._doOpenSpeakerStats();
  550. }
  551. _onToolbarOpenVideoQuality: () => void;
  552. /**
  553. * Creates an analytics toolbar event and dispatches an action for toggling
  554. * open the video quality dialog.
  555. *
  556. * @private
  557. * @returns {void}
  558. */
  559. _onToolbarOpenVideoQuality() {
  560. sendAnalytics(createToolbarEvent('video.quality'));
  561. this._doOpenVideoQuality();
  562. }
  563. _onToolbarToggleChat: () => void;
  564. /**
  565. * Creates an analytics toolbar event and dispatches an action for toggling
  566. * the display of chat.
  567. *
  568. * @private
  569. * @returns {void}
  570. */
  571. _onToolbarToggleChat() {
  572. sendAnalytics(createToolbarEvent(
  573. 'toggle.chat',
  574. {
  575. enable: !this.props._chatOpen
  576. }));
  577. this._doToggleChat();
  578. }
  579. _onToolbarToggleEtherpad: () => void;
  580. /**
  581. * Creates an analytics toolbar event and dispatches an action for toggling
  582. * the display of document editing.
  583. *
  584. * @private
  585. * @returns {void}
  586. */
  587. _onToolbarToggleEtherpad() {
  588. sendAnalytics(createToolbarEvent(
  589. 'toggle.etherpad',
  590. {
  591. enable: !this.props._editingDocument
  592. }));
  593. this._doToggleEtherpad();
  594. }
  595. _onToolbarToggleFullScreen: () => void;
  596. /**
  597. * Creates an analytics toolbar event and dispatches an action for toggling
  598. * full screen mode.
  599. *
  600. * @private
  601. * @returns {void}
  602. */
  603. _onToolbarToggleFullScreen() {
  604. sendAnalytics(createToolbarEvent(
  605. 'toggle.fullscreen',
  606. {
  607. enable: !this.props._fullScreen
  608. }));
  609. this._doToggleFullScreen();
  610. }
  611. _onToolbarToggleProfile: () => void;
  612. /**
  613. * Creates an analytics toolbar event and dispatches an action for showing
  614. * or hiding the profile edit panel.
  615. *
  616. * @private
  617. * @returns {void}
  618. */
  619. _onToolbarToggleProfile() {
  620. sendAnalytics(createToolbarEvent('profile'));
  621. this._doToggleProfile();
  622. }
  623. _onToolbarToggleRaiseHand: () => void;
  624. /**
  625. * Creates an analytics toolbar event and dispatches an action for toggling
  626. * raise hand.
  627. *
  628. * @private
  629. * @returns {void}
  630. */
  631. _onToolbarToggleRaiseHand() {
  632. sendAnalytics(createToolbarEvent(
  633. 'raise.hand',
  634. { enable: !this.props._raisedHand }));
  635. this._doToggleRaiseHand();
  636. }
  637. _onToolbarToggleScreenshare: () => void;
  638. /**
  639. * Creates an analytics toolbar event and dispatches an action for toggling
  640. * screensharing.
  641. *
  642. * @private
  643. * @returns {void}
  644. */
  645. _onToolbarToggleScreenshare() {
  646. if (!this.props._desktopSharingEnabled) {
  647. return;
  648. }
  649. sendAnalytics(createShortcutEvent(
  650. 'toggle.screen.sharing',
  651. ACTION_SHORTCUT_TRIGGERED,
  652. { enable: !this.props._screensharing }));
  653. this._doToggleScreenshare();
  654. }
  655. _onToolbarToggleSharedVideo: () => void;
  656. /**
  657. * Creates an analytics toolbar event and dispatches an action for toggling
  658. * the sharing of a YouTube video.
  659. *
  660. * @private
  661. * @returns {void}
  662. */
  663. _onToolbarToggleSharedVideo() {
  664. sendAnalytics(createToolbarEvent('shared.video.toggled',
  665. {
  666. enable: !this.props._sharingVideo
  667. }));
  668. this._doToggleSharedVideo();
  669. }
  670. _onToolbarOpenLocalRecordingInfoDialog: () => void;
  671. /**
  672. * Opens the {@code LocalRecordingInfoDialog}.
  673. *
  674. * @private
  675. * @returns {void}
  676. */
  677. _onToolbarOpenLocalRecordingInfoDialog() {
  678. sendAnalytics(createToolbarEvent('local.recording'));
  679. this.props.dispatch(openDialog(LocalRecordingInfoDialog));
  680. }
  681. /**
  682. * Renders a button for toggleing screen sharing.
  683. *
  684. * @private
  685. * @returns {ReactElement|null}
  686. */
  687. _renderDesktopSharingButton() {
  688. const {
  689. _desktopSharingEnabled,
  690. _desktopSharingDisabledTooltipKey,
  691. _screensharing,
  692. t
  693. } = this.props;
  694. const visible
  695. = _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  696. if (!visible) {
  697. return null;
  698. }
  699. const classNames = `icon-share-desktop ${
  700. _screensharing ? 'toggled' : ''} ${
  701. _desktopSharingEnabled ? '' : 'disabled'}`;
  702. const tooltip = t(
  703. _desktopSharingEnabled
  704. ? 'dialog.shareYourScreen' : _desktopSharingDisabledTooltipKey);
  705. return (
  706. <ToolbarButton
  707. accessibilityLabel
  708. = { t('toolbar.accessibilityLabel.shareYourScreen') }
  709. iconName = { classNames }
  710. onClick = { this._onToolbarToggleScreenshare }
  711. tooltip = { tooltip } />
  712. );
  713. }
  714. /**
  715. * Renders the list elements of the overflow menu.
  716. *
  717. * @private
  718. * @returns {Array<ReactElement>}
  719. */
  720. _renderOverflowMenuContent() {
  721. const {
  722. _editingDocument,
  723. _etherpadInitialized,
  724. _feedbackConfigured,
  725. _fullScreen,
  726. _isGuest,
  727. _sharingVideo,
  728. t
  729. } = this.props;
  730. return [
  731. _isGuest
  732. && this._shouldShowButton('profile')
  733. && <OverflowMenuProfileItem
  734. key = 'profile'
  735. onClick = { this._onToolbarToggleProfile } />,
  736. this._shouldShowButton('videoquality')
  737. && <OverflowMenuVideoQualityItem
  738. key = 'videoquality'
  739. onClick = { this._onToolbarOpenVideoQuality } />,
  740. this._shouldShowButton('fullscreen')
  741. && <OverflowMenuItem
  742. accessibilityLabel =
  743. { t('toolbar.accessibilityLabel.fullScreen') }
  744. icon = { _fullScreen
  745. ? 'icon-exit-full-screen'
  746. : 'icon-full-screen' }
  747. key = 'fullscreen'
  748. onClick = { this._onToolbarToggleFullScreen }
  749. text = { _fullScreen
  750. ? t('toolbar.exitFullScreen')
  751. : t('toolbar.enterFullScreen') } />,
  752. <LiveStreamButton
  753. key = 'livestreaming'
  754. showLabel = { true } />,
  755. <RecordButton
  756. key = 'record'
  757. showLabel = { true } />,
  758. this._shouldShowButton('sharedvideo')
  759. && <OverflowMenuItem
  760. accessibilityLabel =
  761. { t('toolbar.accessibilityLabel.sharedvideo') }
  762. icon = 'icon-shared-video'
  763. key = 'sharedvideo'
  764. onClick = { this._onToolbarToggleSharedVideo }
  765. text = { _sharingVideo
  766. ? t('toolbar.stopSharedVideo')
  767. : t('toolbar.sharedvideo') } />,
  768. this._shouldShowButton('etherpad')
  769. && _etherpadInitialized
  770. && <OverflowMenuItem
  771. accessibilityLabel =
  772. { t('toolbar.accessibilityLabel.document') }
  773. icon = 'icon-share-doc'
  774. key = 'etherpad'
  775. onClick = { this._onToolbarToggleEtherpad }
  776. text = { _editingDocument
  777. ? t('toolbar.documentClose')
  778. : t('toolbar.documentOpen') } />,
  779. <SettingsButton
  780. key = 'settings'
  781. showLabel = { true }
  782. visible = { this._shouldShowButton('settings') } />,
  783. this._shouldShowButton('stats')
  784. && <OverflowMenuItem
  785. accessibilityLabel =
  786. { t('toolbar.accessibilityLabel.speakerStats') }
  787. icon = 'icon-presentation'
  788. key = 'stats'
  789. onClick = { this._onToolbarOpenSpeakerStats }
  790. text = { t('toolbar.speakerStats') } />,
  791. this._shouldShowButton('feedback')
  792. && _feedbackConfigured
  793. && <OverflowMenuItem
  794. accessibilityLabel =
  795. { t('toolbar.accessibilityLabel.feedback') }
  796. icon = 'icon-feedback'
  797. key = 'feedback'
  798. onClick = { this._onToolbarOpenFeedback }
  799. text = { t('toolbar.feedback') } />,
  800. this._shouldShowButton('shortcuts')
  801. && <OverflowMenuItem
  802. accessibilityLabel =
  803. { t('toolbar.accessibilityLabel.shortcuts') }
  804. icon = 'icon-open_in_new'
  805. key = 'shortcuts'
  806. onClick = { this._onToolbarOpenKeyboardShortcuts }
  807. text = { t('toolbar.shortcuts') } />
  808. ];
  809. }
  810. /**
  811. * Renders the toolbox content.
  812. *
  813. * @returns {Array<ReactElement>}
  814. */
  815. _renderToolboxContent() {
  816. const {
  817. _chatOpen,
  818. _hideInviteButton,
  819. _overflowMenuVisible,
  820. _raisedHand,
  821. t
  822. } = this.props;
  823. const overflowMenuContent = this._renderOverflowMenuContent();
  824. const overflowHasItems = Boolean(overflowMenuContent.filter(
  825. child => child).length);
  826. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  827. return (
  828. <div className = 'toolbox-content'>
  829. <div className = 'button-group-left'>
  830. { this._shouldShowButton('desktop')
  831. && this._renderDesktopSharingButton() }
  832. { this._shouldShowButton('raisehand')
  833. && <ToolbarButton
  834. accessibilityLabel =
  835. {
  836. t('toolbar.accessibilityLabel.raiseHand')
  837. }
  838. iconName = { _raisedHand
  839. ? 'icon-raised-hand toggled'
  840. : 'icon-raised-hand' }
  841. onClick = { this._onToolbarToggleRaiseHand }
  842. tooltip = { t('toolbar.raiseHand') } /> }
  843. { this._shouldShowButton('chat')
  844. && <div className = 'toolbar-button-with-badge'>
  845. <ToolbarButton
  846. accessibilityLabel =
  847. { t('toolbar.accessibilityLabel.chat') }
  848. iconName = { _chatOpen
  849. ? 'icon-chat toggled'
  850. : 'icon-chat' }
  851. onClick = { this._onToolbarToggleChat }
  852. tooltip = { t('toolbar.chat') } />
  853. <ChatCounter />
  854. </div> }
  855. {
  856. this._shouldShowButton('closedcaptions')
  857. && <ClosedCaptionButton />
  858. }
  859. </div>
  860. <div className = 'button-group-center'>
  861. <AudioMuteButton
  862. visible = { this._shouldShowButton('microphone') } />
  863. <HangupButton
  864. visible = { this._shouldShowButton('hangup') } />
  865. <VideoMuteButton
  866. visible = { this._shouldShowButton('camera') } />
  867. </div>
  868. <div className = 'button-group-right'>
  869. { this._shouldShowButton('localrecording')
  870. && <LocalRecordingButton
  871. onClick = {
  872. this._onToolbarOpenLocalRecordingInfoDialog
  873. } />
  874. }
  875. { this._shouldShowButton('tileview')
  876. && <TileViewButton /> }
  877. { this._shouldShowButton('invite')
  878. && !_hideInviteButton
  879. && <ToolbarButton
  880. accessibilityLabel =
  881. { t('toolbar.accessibilityLabel.invite') }
  882. iconName = 'icon-invite'
  883. onClick = { this._onToolbarOpenInvite }
  884. tooltip = { t('toolbar.invite') } /> }
  885. { this._shouldShowButton('info') && <InfoDialogButton /> }
  886. { overflowHasItems
  887. && <OverflowMenuButton
  888. isOpen = { _overflowMenuVisible }
  889. onVisibilityChange = { this._onSetOverflowVisible }>
  890. <ul
  891. aria-label = { t(toolbarAccLabel) }
  892. className = 'overflow-menu'>
  893. { overflowMenuContent }
  894. </ul>
  895. </OverflowMenuButton> }
  896. </div>
  897. </div>);
  898. }
  899. _shouldShowButton: (string) => boolean;
  900. /**
  901. * Returns if a button name has been explicitly configured to be displayed.
  902. *
  903. * @param {string} buttonName - The name of the button, as expected in
  904. * {@link interfaceConfig}.
  905. * @private
  906. * @returns {boolean} True if the button should be displayed.
  907. */
  908. _shouldShowButton(buttonName) {
  909. return this.props._visibleButtons.has(buttonName);
  910. }
  911. }
  912. /**
  913. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  914. * props.
  915. *
  916. * @param {Object} state - The redux store/state.
  917. * @private
  918. * @returns {{}}
  919. */
  920. function _mapStateToProps(state) {
  921. const { conference } = state['features/base/conference'];
  922. let { desktopSharingEnabled } = state['features/base/conference'];
  923. const {
  924. callStatsID,
  925. iAmRecorder
  926. } = state['features/base/config'];
  927. const sharedVideoStatus = state['features/shared-video'].status;
  928. const {
  929. alwaysVisible,
  930. fullScreen,
  931. overflowMenuVisible,
  932. timeoutID,
  933. visible
  934. } = state['features/toolbox'];
  935. const localParticipant = getLocalParticipant(state);
  936. const localRecordingStates = state['features/local-recording'];
  937. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  938. const addPeopleEnabled = isAddPeopleEnabled(state);
  939. const dialOutEnabled = isDialOutEnabled(state);
  940. let desktopSharingDisabledTooltipKey;
  941. if (state['features/base/config'].enableFeaturesBasedOnToken) {
  942. // we enable desktop sharing if any participant already have this
  943. // feature enabled
  944. desktopSharingEnabled = getParticipants(state)
  945. .find(({ features = {} }) =>
  946. String(features['screen-sharing']) === 'true') !== undefined;
  947. // we want to show button and tooltip
  948. if (state['features/base/jwt'].isGuest) {
  949. desktopSharingDisabledTooltipKey
  950. = 'dialog.shareYourScreenDisabledForGuest';
  951. } else {
  952. desktopSharingDisabledTooltipKey
  953. = 'dialog.shareYourScreenDisabled';
  954. }
  955. }
  956. return {
  957. _chatOpen: state['features/chat'].isOpen,
  958. _conference: conference,
  959. _desktopSharingEnabled: desktopSharingEnabled,
  960. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  961. _dialog: Boolean(state['features/base/dialog'].component),
  962. _editingDocument: Boolean(state['features/etherpad'].editing),
  963. _etherpadInitialized: Boolean(state['features/etherpad'].initialized),
  964. _feedbackConfigured: Boolean(callStatsID),
  965. _hideInviteButton:
  966. iAmRecorder || (!addPeopleEnabled && !dialOutEnabled),
  967. _isGuest: state['features/base/jwt'].isGuest,
  968. _fullScreen: fullScreen,
  969. _localParticipantID: localParticipant.id,
  970. _localRecState: localRecordingStates,
  971. _overflowMenuVisible: overflowMenuVisible,
  972. _raisedHand: localParticipant.raisedHand,
  973. _screensharing: localVideo && localVideo.videoType === 'desktop',
  974. _sharingVideo: sharedVideoStatus === 'playing'
  975. || sharedVideoStatus === 'start'
  976. || sharedVideoStatus === 'pause',
  977. _visible: Boolean(timeoutID || visible || alwaysVisible),
  978. // XXX: We are not currently using state here, but in the future, when
  979. // interfaceConfig is part of redux we will.
  980. _visibleButtons: new Set(interfaceConfig.TOOLBAR_BUTTONS)
  981. };
  982. }
  983. export default translate(connect(_mapStateToProps)(Toolbox));