You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbox.js 40KB

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