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

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