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

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