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

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