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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. // @flow
  2. import React, { Component, Fragment } from 'react';
  3. import keyboardShortcut from '../../../../../modules/keyboardshortcut/keyboardshortcut';
  4. import {
  5. ACTION_SHORTCUT_TRIGGERED,
  6. createShortcutEvent,
  7. createToolbarEvent,
  8. sendAnalytics
  9. } from '../../../analytics';
  10. import { getToolbarButtons } from '../../../base/config';
  11. import { isToolbarButtonEnabled } from '../../../base/config/functions.web';
  12. import { openDialog, toggleDialog } from '../../../base/dialog';
  13. import { isMobileBrowser } from '../../../base/environment/utils';
  14. import { translate } from '../../../base/i18n';
  15. import JitsiMeetJS from '../../../base/lib-jitsi-meet';
  16. import {
  17. getLocalParticipant,
  18. haveParticipantWithScreenSharingFeature,
  19. raiseHand
  20. } from '../../../base/participants';
  21. import { connect } from '../../../base/redux';
  22. import { getLocalVideoTrack } from '../../../base/tracks';
  23. import { toggleChat } from '../../../chat';
  24. import { ChatButton } from '../../../chat/components';
  25. import { DominantSpeakerName } from '../../../display-name';
  26. import { EmbedMeetingButton } from '../../../embed-meeting';
  27. import { SharedDocumentButton } from '../../../etherpad';
  28. import { FeedbackButton } from '../../../feedback';
  29. import { InviteButton } from '../../../invite/components/add-people-dialog';
  30. import { isVpaasMeeting } from '../../../jaas/functions';
  31. import { KeyboardShortcutsButton } from '../../../keyboard-shortcuts';
  32. import { LocalRecordingButton } from '../../../local-recording';
  33. import {
  34. close as closeParticipantsPane,
  35. open as openParticipantsPane
  36. } from '../../../participants-pane/actions';
  37. import ParticipantsPaneButton from '../../../participants-pane/components/ParticipantsPaneButton';
  38. import { getParticipantsPaneOpen } from '../../../participants-pane/functions';
  39. import { addReactionToBuffer } from '../../../reactions/actions.any';
  40. import { ReactionsMenuButton } from '../../../reactions/components';
  41. import { REACTIONS } from '../../../reactions/constants';
  42. import { isReactionsEnabled } from '../../../reactions/functions.any';
  43. import {
  44. LiveStreamButton,
  45. RecordButton
  46. } from '../../../recording';
  47. import {
  48. isScreenAudioSupported,
  49. isScreenVideoShared,
  50. ShareAudioButton,
  51. startScreenShareFlow
  52. } from '../../../screen-share/';
  53. import SecurityDialogButton from '../../../security/components/security-dialog/SecurityDialogButton';
  54. import { SettingsButton } from '../../../settings';
  55. import { SharedVideoButton } from '../../../shared-video/components';
  56. import { SpeakerStatsButton } from '../../../speaker-stats';
  57. import {
  58. ClosedCaptionButton
  59. } from '../../../subtitles';
  60. import {
  61. TileViewButton,
  62. shouldDisplayTileView,
  63. toggleTileView
  64. } from '../../../video-layout';
  65. import { VideoQualityDialog, VideoQualityButton } from '../../../video-quality/components';
  66. import { VideoBackgroundButton } from '../../../virtual-background';
  67. import { toggleBackgroundEffect } from '../../../virtual-background/actions';
  68. import { VIRTUAL_BACKGROUND_TYPE } from '../../../virtual-background/constants';
  69. import {
  70. setFullScreen,
  71. setOverflowMenuVisible,
  72. setToolbarHovered,
  73. showToolbox
  74. } from '../../actions';
  75. import { THRESHOLDS, NOT_APPLICABLE } from '../../constants';
  76. import { isToolboxVisible } from '../../functions';
  77. import DownloadButton from '../DownloadButton';
  78. import HangupButton from '../HangupButton';
  79. import HelpButton from '../HelpButton';
  80. import MuteEveryoneButton from '../MuteEveryoneButton';
  81. import MuteEveryonesVideoButton from '../MuteEveryonesVideoButton';
  82. import AudioSettingsButton from './AudioSettingsButton';
  83. import FullscreenButton from './FullscreenButton';
  84. import OverflowMenuButton from './OverflowMenuButton';
  85. import ProfileButton from './ProfileButton';
  86. import Separator from './Separator';
  87. import ShareDesktopButton from './ShareDesktopButton';
  88. import ToggleCameraButton from './ToggleCameraButton';
  89. import VideoSettingsButton from './VideoSettingsButton';
  90. /**
  91. * The type of the React {@code Component} props of {@link Toolbox}.
  92. */
  93. type Props = {
  94. /**
  95. * String showing if the virtual background type is desktop-share.
  96. */
  97. _backgroundType: String,
  98. /**
  99. * Toolbar buttons which have their click exposed through the API.
  100. */
  101. _buttonsWithNotifyClick: Array<string>,
  102. /**
  103. * Whether or not the chat feature is currently displayed.
  104. */
  105. _chatOpen: boolean,
  106. /**
  107. * The width of the client.
  108. */
  109. _clientWidth: number,
  110. /**
  111. * The {@code JitsiConference} for the current conference.
  112. */
  113. _conference: Object,
  114. /**
  115. * The tooltip key to use when screensharing is disabled. Or undefined
  116. * if non to be shown and the button to be hidden.
  117. */
  118. _desktopSharingDisabledTooltipKey: boolean,
  119. /**
  120. * Whether or not screensharing is initialized.
  121. */
  122. _desktopSharingEnabled: boolean,
  123. /**
  124. * Whether or not a dialog is displayed.
  125. */
  126. _dialog: boolean,
  127. /**
  128. * Whether or not call feedback can be sent.
  129. */
  130. _feedbackConfigured: boolean,
  131. /**
  132. * Whether or not the app is currently in full screen.
  133. */
  134. _fullScreen: boolean,
  135. /**
  136. * Whether or not the app is running in mobile browser.
  137. */
  138. _isMobile: boolean,
  139. /**
  140. * Whether or not the profile is disabled.
  141. */
  142. _isProfileDisabled: boolean,
  143. /**
  144. * Whether or not the current meeting belongs to a JaaS user.
  145. */
  146. _isVpaasMeeting: boolean,
  147. /**
  148. * The ID of the local participant.
  149. */
  150. _localParticipantID: String,
  151. /**
  152. * The JitsiLocalTrack to display.
  153. */
  154. _localVideo: Object,
  155. /**
  156. * Whether or not the overflow menu is visible.
  157. */
  158. _overflowMenuVisible: boolean,
  159. /**
  160. * Whether or not the participants pane is open.
  161. */
  162. _participantsPaneOpen: boolean,
  163. /**
  164. * Whether or not the local participant's hand is raised.
  165. */
  166. _raisedHand: boolean,
  167. /**
  168. * Whether or not reactions feature is enabled.
  169. */
  170. _reactionsEnabled: boolean,
  171. /**
  172. * Whether or not the local participant is screenSharing.
  173. */
  174. _screenSharing: boolean,
  175. /**
  176. * Whether or not the local participant is sharing a YouTube video.
  177. */
  178. _sharingVideo: boolean,
  179. /**
  180. * Whether or not the tile view is enabled.
  181. */
  182. _tileViewEnabled: boolean,
  183. /**
  184. * The enabled buttons.
  185. */
  186. _toolbarButtons: Array<string>,
  187. /**
  188. * Flag showing whether toolbar is visible.
  189. */
  190. _visible: boolean,
  191. /**
  192. * Returns the selected virtual source object.
  193. */
  194. _virtualSource: Object,
  195. /**
  196. * Invoked to active other features of the app.
  197. */
  198. dispatch: Function,
  199. /**
  200. * If the dominant speaker name should be displayed or not.
  201. */
  202. showDominantSpeakerName?: boolean,
  203. /**
  204. * Invoked to obtain translated strings.
  205. */
  206. t: Function,
  207. /**
  208. * Explicitly passed array with the buttons which this Toolbox should display.
  209. */
  210. toolbarButtons: Array<string>,
  211. };
  212. declare var APP: Object;
  213. /**
  214. * Implements the conference toolbox on React/Web.
  215. *
  216. * @extends Component
  217. */
  218. class Toolbox extends Component<Props> {
  219. /**
  220. * Initializes a new {@code Toolbox} instance.
  221. *
  222. * @param {Props} props - The read-only React {@code Component} props with
  223. * which the new instance is to be initialized.
  224. */
  225. constructor(props: Props) {
  226. super(props);
  227. // Bind event handlers so they are only bound once per instance.
  228. this._onMouseOut = this._onMouseOut.bind(this);
  229. this._onMouseOver = this._onMouseOver.bind(this);
  230. this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
  231. this._onTabIn = this._onTabIn.bind(this);
  232. this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
  233. this._onShortcutToggleFullScreen = this._onShortcutToggleFullScreen.bind(this);
  234. this._onShortcutToggleParticipantsPane = this._onShortcutToggleParticipantsPane.bind(this);
  235. this._onShortcutToggleRaiseHand = this._onShortcutToggleRaiseHand.bind(this);
  236. this._onShortcutToggleScreenshare = this._onShortcutToggleScreenshare.bind(this);
  237. this._onShortcutToggleVideoQuality = this._onShortcutToggleVideoQuality.bind(this);
  238. this._onToolbarToggleParticipantsPane = this._onToolbarToggleParticipantsPane.bind(this);
  239. this._onToolbarOpenVideoQuality = this._onToolbarOpenVideoQuality.bind(this);
  240. this._onToolbarToggleChat = this._onToolbarToggleChat.bind(this);
  241. this._onToolbarToggleFullScreen = this._onToolbarToggleFullScreen.bind(this);
  242. this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
  243. this._onToolbarToggleScreenshare = this._onToolbarToggleScreenshare.bind(this);
  244. this._onShortcutToggleTileView = this._onShortcutToggleTileView.bind(this);
  245. this._onEscKey = this._onEscKey.bind(this);
  246. }
  247. /**
  248. * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
  249. *
  250. * @inheritdoc
  251. * @returns {void}
  252. */
  253. componentDidMount() {
  254. const { _toolbarButtons, t, dispatch, _reactionsEnabled } = this.props;
  255. const KEYBOARD_SHORTCUTS = [
  256. isToolbarButtonEnabled('videoquality', _toolbarButtons) && {
  257. character: 'A',
  258. exec: this._onShortcutToggleVideoQuality,
  259. helpDescription: 'toolbar.callQuality'
  260. },
  261. isToolbarButtonEnabled('chat', _toolbarButtons) && {
  262. character: 'C',
  263. exec: this._onShortcutToggleChat,
  264. helpDescription: 'keyboardShortcuts.toggleChat'
  265. },
  266. isToolbarButtonEnabled('desktop', _toolbarButtons) && {
  267. character: 'D',
  268. exec: this._onShortcutToggleScreenshare,
  269. helpDescription: 'keyboardShortcuts.toggleScreensharing'
  270. },
  271. isToolbarButtonEnabled('participants-pane', _toolbarButtons) && {
  272. character: 'P',
  273. exec: this._onShortcutToggleParticipantsPane,
  274. helpDescription: 'keyboardShortcuts.toggleParticipantsPane'
  275. },
  276. isToolbarButtonEnabled('raisehand', _toolbarButtons) && {
  277. character: 'R',
  278. exec: this._onShortcutToggleRaiseHand,
  279. helpDescription: 'keyboardShortcuts.raiseHand'
  280. },
  281. isToolbarButtonEnabled('fullscreen', _toolbarButtons) && {
  282. character: 'S',
  283. exec: this._onShortcutToggleFullScreen,
  284. helpDescription: 'keyboardShortcuts.fullScreen'
  285. },
  286. isToolbarButtonEnabled('tileview', _toolbarButtons) && {
  287. character: 'W',
  288. exec: this._onShortcutToggleTileView,
  289. helpDescription: 'toolbar.tileViewToggle'
  290. }
  291. ];
  292. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  293. if (typeof shortcut === 'object') {
  294. APP.keyboardshortcut.registerShortcut(
  295. shortcut.character,
  296. null,
  297. shortcut.exec,
  298. shortcut.helpDescription);
  299. }
  300. });
  301. if (_reactionsEnabled) {
  302. const REACTION_SHORTCUTS = Object.keys(REACTIONS).map(key => {
  303. const onShortcutSendReaction = () => {
  304. dispatch(addReactionToBuffer(key));
  305. sendAnalytics(createShortcutEvent(
  306. `reaction.${key}`
  307. ));
  308. };
  309. return {
  310. character: REACTIONS[key].shortcutChar,
  311. exec: onShortcutSendReaction,
  312. helpDescription: t(`toolbar.reaction${key.charAt(0).toUpperCase()}${key.slice(1)}`),
  313. altKey: true
  314. };
  315. });
  316. REACTION_SHORTCUTS.forEach(shortcut => {
  317. APP.keyboardshortcut.registerShortcut(
  318. shortcut.character,
  319. null,
  320. shortcut.exec,
  321. shortcut.helpDescription,
  322. shortcut.altKey);
  323. });
  324. }
  325. }
  326. /**
  327. * Update the visibility of the {@code OverflowMenuButton}.
  328. *
  329. * @inheritdoc
  330. */
  331. componentDidUpdate(prevProps) {
  332. const { _dialog, dispatch } = this.props;
  333. if (prevProps._overflowMenuVisible
  334. && !prevProps._dialog
  335. && _dialog) {
  336. this._onSetOverflowVisible(false);
  337. dispatch(setToolbarHovered(false));
  338. }
  339. }
  340. /**
  341. * Removes keyboard shortcuts registered by this component.
  342. *
  343. * @inheritdoc
  344. * @returns {void}
  345. */
  346. componentWillUnmount() {
  347. [ 'A', 'C', 'D', 'R', 'S' ].forEach(letter =>
  348. APP.keyboardshortcut.unregisterShortcut(letter));
  349. if (this.props._reactionsEnabled) {
  350. Object.keys(REACTIONS).map(key => REACTIONS[key].shortcutChar)
  351. .forEach(letter =>
  352. APP.keyboardshortcut.unregisterShortcut(letter, true));
  353. }
  354. }
  355. /**
  356. * Implements React's {@link Component#render()}.
  357. *
  358. * @inheritdoc
  359. * @returns {ReactElement}
  360. */
  361. render() {
  362. const { _chatOpen, _visible, _toolbarButtons } = this.props;
  363. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  364. _toolbarButtons.length ? '' : 'no-buttons'} ${_chatOpen ? 'shift-right' : ''}`;
  365. return (
  366. <div
  367. className = { rootClassNames }
  368. id = 'new-toolbox'>
  369. { this._renderToolboxContent() }
  370. </div>
  371. );
  372. }
  373. _onEscKey: (KeyboardEvent) => void;
  374. /**
  375. * Key handler for overflow menu.
  376. *
  377. * @param {KeyboardEvent} e - Esc key click to close the popup.
  378. * @returns {void}
  379. */
  380. _onEscKey(e) {
  381. if (e.key === 'Escape') {
  382. e.stopPropagation();
  383. this._closeOverflowMenuIfOpen();
  384. }
  385. }
  386. /**
  387. * Closes the overflow menu if opened.
  388. *
  389. * @private
  390. * @returns {void}
  391. */
  392. _closeOverflowMenuIfOpen() {
  393. const { dispatch, _overflowMenuVisible } = this.props;
  394. _overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
  395. }
  396. /**
  397. * Dispatches an action to open the video quality dialog.
  398. *
  399. * @private
  400. * @returns {void}
  401. */
  402. _doOpenVideoQuality() {
  403. this.props.dispatch(openDialog(VideoQualityDialog));
  404. }
  405. /**
  406. * Dispatches an action to toggle the display of chat.
  407. *
  408. * @private
  409. * @returns {void}
  410. */
  411. _doToggleChat() {
  412. this.props.dispatch(toggleChat());
  413. }
  414. /**
  415. * Dispatches an action to toggle screensharing.
  416. *
  417. * @private
  418. * @returns {void}
  419. */
  420. _doToggleFullScreen() {
  421. const fullScreen = !this.props._fullScreen;
  422. this.props.dispatch(setFullScreen(fullScreen));
  423. }
  424. /**
  425. * Dispatches an action to toggle the local participant's raised hand state.
  426. *
  427. * @private
  428. * @returns {void}
  429. */
  430. _doToggleRaiseHand() {
  431. const { _localParticipantID, _raisedHand } = this.props;
  432. const newRaisedStatus = !_raisedHand;
  433. this.props.dispatch(raiseHand(newRaisedStatus));
  434. APP.API.notifyRaiseHandUpdated(_localParticipantID, newRaisedStatus);
  435. }
  436. /**
  437. * Dispatches an action to toggle screensharing.
  438. *
  439. * @private
  440. * @param {boolean} enabled - The state to toggle screen sharing to.
  441. * @param {boolean} audioOnly - Only share system audio.
  442. * @returns {void}
  443. */
  444. _doToggleScreenshare() {
  445. const {
  446. _backgroundType,
  447. _desktopSharingEnabled,
  448. _localVideo,
  449. _virtualSource,
  450. dispatch
  451. } = this.props;
  452. if (_backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
  453. const noneOptions = {
  454. enabled: false,
  455. backgroundType: VIRTUAL_BACKGROUND_TYPE.NONE,
  456. selectedThumbnail: VIRTUAL_BACKGROUND_TYPE.NONE,
  457. backgroundEffectEnabled: false
  458. };
  459. _virtualSource.dispose();
  460. dispatch(toggleBackgroundEffect(noneOptions, _localVideo));
  461. return;
  462. }
  463. if (_desktopSharingEnabled) {
  464. dispatch(startScreenShareFlow());
  465. }
  466. }
  467. /**
  468. * Dispatches an action to toggle the video quality dialog.
  469. *
  470. * @private
  471. * @returns {void}
  472. */
  473. _doToggleVideoQuality() {
  474. this.props.dispatch(toggleDialog(VideoQualityDialog));
  475. }
  476. /**
  477. * Dispaches an action to toggle tile view.
  478. *
  479. * @private
  480. * @returns {void}
  481. */
  482. _doToggleTileView() {
  483. this.props.dispatch(toggleTileView());
  484. }
  485. /**
  486. * Returns all buttons that could be rendered.
  487. *
  488. * @param {Object} state - The redux state.
  489. * @returns {Object} The button maps mainMenuButtons and overflowMenuButtons.
  490. */
  491. _getAllButtons() {
  492. const {
  493. _feedbackConfigured,
  494. _isMobile,
  495. _screenSharing
  496. } = this.props;
  497. const microphone = {
  498. key: 'microphone',
  499. Content: AudioSettingsButton,
  500. group: 0
  501. };
  502. const camera = {
  503. key: 'camera',
  504. Content: VideoSettingsButton,
  505. group: 0
  506. };
  507. const profile = this._isProfileVisible() && {
  508. key: 'profile',
  509. Content: ProfileButton,
  510. group: 1
  511. };
  512. const chat = {
  513. key: 'chat',
  514. Content: ChatButton,
  515. handleClick: this._onToolbarToggleChat,
  516. group: 2
  517. };
  518. const desktop = this._showDesktopSharingButton() && {
  519. key: 'desktop',
  520. Content: ShareDesktopButton,
  521. handleClick: this._onToolbarToggleScreenshare,
  522. group: 2
  523. };
  524. const raisehand = {
  525. key: 'raisehand',
  526. Content: ReactionsMenuButton,
  527. handleClick: this._onToolbarToggleRaiseHand,
  528. group: 2
  529. };
  530. const participants = {
  531. key: 'participants-pane',
  532. Content: ParticipantsPaneButton,
  533. handleClick: this._onToolbarToggleParticipantsPane,
  534. group: 2
  535. };
  536. const invite = {
  537. key: 'invite',
  538. Content: InviteButton,
  539. group: 2
  540. };
  541. const tileview = {
  542. key: 'tileview',
  543. Content: TileViewButton,
  544. group: 2
  545. };
  546. const toggleCamera = {
  547. key: 'toggle-camera',
  548. Content: ToggleCameraButton,
  549. group: 2
  550. };
  551. const videoQuality = {
  552. key: 'videoquality',
  553. Content: VideoQualityButton,
  554. handleClick: this._onToolbarOpenVideoQuality,
  555. group: 2
  556. };
  557. const fullscreen = !_isMobile && {
  558. key: 'fullscreen',
  559. Content: FullscreenButton,
  560. handleClick: this._onToolbarToggleFullScreen,
  561. group: 2
  562. };
  563. const security = {
  564. key: 'security',
  565. alias: 'info',
  566. Content: SecurityDialogButton,
  567. group: 2
  568. };
  569. const cc = {
  570. key: 'closedcaptions',
  571. Content: ClosedCaptionButton,
  572. group: 2
  573. };
  574. const recording = {
  575. key: 'recording',
  576. Content: RecordButton,
  577. group: 2
  578. };
  579. const localRecording = {
  580. key: 'localrecording',
  581. Content: LocalRecordingButton,
  582. group: 2
  583. };
  584. const livestreaming = {
  585. key: 'livestreaming',
  586. Content: LiveStreamButton,
  587. group: 2
  588. };
  589. const muteEveryone = {
  590. key: 'mute-everyone',
  591. Content: MuteEveryoneButton,
  592. group: 2
  593. };
  594. const muteVideoEveryone = {
  595. key: 'mute-video-everyone',
  596. Content: MuteEveryonesVideoButton,
  597. group: 2
  598. };
  599. const shareVideo = {
  600. key: 'sharedvideo',
  601. Content: SharedVideoButton,
  602. group: 3
  603. };
  604. const shareAudio = this._showAudioSharingButton() && {
  605. key: 'shareaudio',
  606. Content: ShareAudioButton,
  607. group: 3
  608. };
  609. const etherpad = {
  610. key: 'etherpad',
  611. Content: SharedDocumentButton,
  612. group: 3
  613. };
  614. const virtualBackground = !_screenSharing && {
  615. key: 'select-background',
  616. Content: VideoBackgroundButton,
  617. group: 3
  618. };
  619. const speakerStats = {
  620. key: 'stats',
  621. Content: SpeakerStatsButton,
  622. group: 3
  623. };
  624. const settings = {
  625. key: 'settings',
  626. Content: SettingsButton,
  627. group: 4
  628. };
  629. const shortcuts = !_isMobile && keyboardShortcut.getEnabled() && {
  630. key: 'shortcuts',
  631. Content: KeyboardShortcutsButton,
  632. group: 4
  633. };
  634. const embed = this._isEmbedMeetingVisible() && {
  635. key: 'embedmeeting',
  636. Content: EmbedMeetingButton,
  637. group: 4
  638. };
  639. const feedback = _feedbackConfigured && {
  640. key: 'feedback',
  641. Content: FeedbackButton,
  642. group: 4
  643. };
  644. const download = {
  645. key: 'download',
  646. Content: DownloadButton,
  647. group: 4
  648. };
  649. const help = {
  650. key: 'help',
  651. Content: HelpButton,
  652. group: 4
  653. };
  654. return {
  655. microphone,
  656. camera,
  657. profile,
  658. desktop,
  659. chat,
  660. raisehand,
  661. participants,
  662. invite,
  663. tileview,
  664. toggleCamera,
  665. videoQuality,
  666. fullscreen,
  667. security,
  668. cc,
  669. recording,
  670. localRecording,
  671. livestreaming,
  672. muteEveryone,
  673. muteVideoEveryone,
  674. shareVideo,
  675. shareAudio,
  676. etherpad,
  677. virtualBackground,
  678. speakerStats,
  679. settings,
  680. shortcuts,
  681. embed,
  682. feedback,
  683. download,
  684. help
  685. };
  686. }
  687. /**
  688. * Overwrites click handlers for buttons in case click is exposed through the iframe API.
  689. *
  690. * @param {Object} buttons - The list of toolbar buttons.
  691. * @returns {void}
  692. */
  693. _overwriteButtonsClickHandlers(buttons) {
  694. if (typeof APP === 'undefined' || !this.props._buttonsWithNotifyClick?.length) {
  695. return;
  696. }
  697. Object.values(buttons).forEach((button: any) => {
  698. if (this.props._buttonsWithNotifyClick.includes(button.key)) {
  699. button.handleClick = () => APP.API.notifyToolbarButtonClicked(button.key);
  700. }
  701. });
  702. }
  703. /**
  704. * Returns all buttons that need to be rendered.
  705. *
  706. * @param {Object} state - The redux state.
  707. * @returns {Object} The visible buttons arrays .
  708. */
  709. _getVisibleButtons() {
  710. const {
  711. _clientWidth,
  712. _toolbarButtons
  713. } = this.props;
  714. const buttons = this._getAllButtons();
  715. this._overwriteButtonsClickHandlers(buttons);
  716. const isHangupVisible = isToolbarButtonEnabled('hangup', _toolbarButtons);
  717. const { order } = THRESHOLDS.find(({ width }) => _clientWidth > width)
  718. || THRESHOLDS[THRESHOLDS.length - 1];
  719. let sliceIndex = order.length + 2;
  720. const keys = Object.keys(buttons);
  721. const filtered = [
  722. ...order.map(key => buttons[key]),
  723. ...Object.values(buttons).filter((button, index) => !order.includes(keys[index]))
  724. ].filter(Boolean).filter(({ key, alias = NOT_APPLICABLE }) =>
  725. isToolbarButtonEnabled(key, _toolbarButtons) || isToolbarButtonEnabled(alias, _toolbarButtons));
  726. if (isHangupVisible) {
  727. sliceIndex -= 1;
  728. }
  729. // This implies that the overflow button will be displayed, so save some space for it.
  730. if (sliceIndex < filtered.length) {
  731. sliceIndex -= 1;
  732. }
  733. return {
  734. mainMenuButtons: filtered.slice(0, sliceIndex),
  735. overflowMenuButtons: filtered.slice(sliceIndex)
  736. };
  737. }
  738. _onMouseOut: () => void;
  739. /**
  740. * Dispatches an action signaling the toolbar is not being hovered.
  741. *
  742. * @private
  743. * @returns {void}
  744. */
  745. _onMouseOut() {
  746. const { _overflowMenuVisible, dispatch } = this.props;
  747. !_overflowMenuVisible && dispatch(setToolbarHovered(false));
  748. }
  749. _onMouseOver: () => void;
  750. /**
  751. * Dispatches an action signaling the toolbar is being hovered.
  752. *
  753. * @private
  754. * @returns {void}
  755. */
  756. _onMouseOver() {
  757. this.props.dispatch(setToolbarHovered(true));
  758. }
  759. _onSetOverflowVisible: (boolean) => void;
  760. /**
  761. * Sets the visibility of the overflow menu.
  762. *
  763. * @param {boolean} visible - Whether or not the overflow menu should be
  764. * displayed.
  765. * @private
  766. * @returns {void}
  767. */
  768. _onSetOverflowVisible(visible) {
  769. this.props.dispatch(setOverflowMenuVisible(visible));
  770. this.props.dispatch(setToolbarHovered(visible));
  771. }
  772. _onShortcutToggleChat: () => void;
  773. /**
  774. * Creates an analytics keyboard shortcut event and dispatches an action for
  775. * toggling the display of chat.
  776. *
  777. * @private
  778. * @returns {void}
  779. */
  780. _onShortcutToggleChat() {
  781. sendAnalytics(createShortcutEvent(
  782. 'toggle.chat',
  783. {
  784. enable: !this.props._chatOpen
  785. }));
  786. // Checks if there was any text selected by the user.
  787. // Used for when we press simultaneously keys for copying
  788. // text messages from the chat board
  789. if (window.getSelection().toString() !== '') {
  790. return false;
  791. }
  792. this._doToggleChat();
  793. }
  794. _onShortcutToggleParticipantsPane: () => void;
  795. /**
  796. * Creates an analytics keyboard shortcut event and dispatches an action for
  797. * toggling the display of the participants pane.
  798. *
  799. * @private
  800. * @returns {void}
  801. */
  802. _onShortcutToggleParticipantsPane() {
  803. sendAnalytics(createShortcutEvent(
  804. 'toggle.participants-pane',
  805. {
  806. enable: !this.props._participantsPaneOpen
  807. }));
  808. this._onToolbarToggleParticipantsPane();
  809. }
  810. _onShortcutToggleVideoQuality: () => void;
  811. /**
  812. * Creates an analytics keyboard shortcut event and dispatches an action for
  813. * toggling the display of Video Quality.
  814. *
  815. * @private
  816. * @returns {void}
  817. */
  818. _onShortcutToggleVideoQuality() {
  819. sendAnalytics(createShortcutEvent('video.quality'));
  820. this._doToggleVideoQuality();
  821. }
  822. _onShortcutToggleTileView: () => void;
  823. /**
  824. * Dispatches an action for toggling the tile view.
  825. *
  826. * @private
  827. * @returns {void}
  828. */
  829. _onShortcutToggleTileView() {
  830. sendAnalytics(createShortcutEvent(
  831. 'toggle.tileview',
  832. {
  833. enable: !this.props._tileViewEnabled
  834. }));
  835. this._doToggleTileView();
  836. }
  837. _onShortcutToggleFullScreen: () => void;
  838. /**
  839. * Creates an analytics keyboard shortcut event and dispatches an action for
  840. * toggling full screen mode.
  841. *
  842. * @private
  843. * @returns {void}
  844. */
  845. _onShortcutToggleFullScreen() {
  846. sendAnalytics(createShortcutEvent(
  847. 'toggle.fullscreen',
  848. {
  849. enable: !this.props._fullScreen
  850. }));
  851. this._doToggleFullScreen();
  852. }
  853. _onShortcutToggleRaiseHand: () => void;
  854. /**
  855. * Creates an analytics keyboard shortcut event and dispatches an action for
  856. * toggling raise hand.
  857. *
  858. * @private
  859. * @returns {void}
  860. */
  861. _onShortcutToggleRaiseHand() {
  862. sendAnalytics(createShortcutEvent(
  863. 'toggle.raise.hand',
  864. ACTION_SHORTCUT_TRIGGERED,
  865. { enable: !this.props._raisedHand }));
  866. this._doToggleRaiseHand();
  867. }
  868. _onShortcutToggleScreenshare: () => void;
  869. /**
  870. * Creates an analytics keyboard shortcut event and dispatches an action for
  871. * toggling screensharing.
  872. *
  873. * @private
  874. * @returns {void}
  875. */
  876. _onShortcutToggleScreenshare() {
  877. sendAnalytics(createShortcutEvent(
  878. 'toggle.screen.sharing',
  879. ACTION_SHORTCUT_TRIGGERED,
  880. {
  881. enable: !this.props._screenSharing
  882. }));
  883. this._doToggleScreenshare();
  884. }
  885. _onTabIn: () => void;
  886. /**
  887. * Toggle the toolbar visibility when tabbing into it.
  888. *
  889. * @returns {void}
  890. */
  891. _onTabIn() {
  892. if (!this.props._visible) {
  893. this.props.dispatch(showToolbox());
  894. }
  895. }
  896. _onToolbarToggleParticipantsPane: () => void;
  897. /**
  898. * Dispatches an action for toggling the participants pane.
  899. *
  900. * @private
  901. * @returns {void}
  902. */
  903. _onToolbarToggleParticipantsPane() {
  904. const { dispatch, _participantsPaneOpen } = this.props;
  905. if (_participantsPaneOpen) {
  906. dispatch(closeParticipantsPane());
  907. } else {
  908. dispatch(openParticipantsPane());
  909. }
  910. }
  911. _onToolbarOpenVideoQuality: () => void;
  912. /**
  913. * Creates an analytics toolbar event and dispatches an action for toggling
  914. * open the video quality dialog.
  915. *
  916. * @private
  917. * @returns {void}
  918. */
  919. _onToolbarOpenVideoQuality() {
  920. sendAnalytics(createToolbarEvent('video.quality'));
  921. this._doOpenVideoQuality();
  922. }
  923. _onToolbarToggleChat: () => void;
  924. /**
  925. * Creates an analytics toolbar event and dispatches an action for toggling
  926. * the display of chat.
  927. *
  928. * @private
  929. * @returns {void}
  930. */
  931. _onToolbarToggleChat() {
  932. sendAnalytics(createToolbarEvent(
  933. 'toggle.chat',
  934. {
  935. enable: !this.props._chatOpen
  936. }));
  937. this._closeOverflowMenuIfOpen();
  938. this._doToggleChat();
  939. }
  940. _onToolbarToggleFullScreen: () => void;
  941. /**
  942. * Creates an analytics toolbar event and dispatches an action for toggling
  943. * full screen mode.
  944. *
  945. * @private
  946. * @returns {void}
  947. */
  948. _onToolbarToggleFullScreen() {
  949. sendAnalytics(createToolbarEvent(
  950. 'toggle.fullscreen',
  951. {
  952. enable: !this.props._fullScreen
  953. }));
  954. this._closeOverflowMenuIfOpen();
  955. this._doToggleFullScreen();
  956. }
  957. _onToolbarToggleRaiseHand: () => void;
  958. /**
  959. * Creates an analytics toolbar event and dispatches an action for toggling
  960. * raise hand.
  961. *
  962. * @private
  963. * @returns {void}
  964. */
  965. _onToolbarToggleRaiseHand() {
  966. sendAnalytics(createToolbarEvent(
  967. 'raise.hand',
  968. { enable: !this.props._raisedHand }));
  969. this._doToggleRaiseHand();
  970. }
  971. _onToolbarToggleScreenshare: () => void;
  972. /**
  973. * Creates an analytics toolbar event and dispatches an action for toggling
  974. * screensharing.
  975. *
  976. * @private
  977. * @returns {void}
  978. */
  979. _onToolbarToggleScreenshare() {
  980. sendAnalytics(createToolbarEvent(
  981. 'toggle.screen.sharing',
  982. ACTION_SHORTCUT_TRIGGERED,
  983. { enable: !this.props._screenSharing }));
  984. this._closeOverflowMenuIfOpen();
  985. this._doToggleScreenshare();
  986. }
  987. /**
  988. * Returns true if the audio sharing button should be visible and
  989. * false otherwise.
  990. *
  991. * @returns {boolean}
  992. */
  993. _showAudioSharingButton() {
  994. const {
  995. _desktopSharingEnabled
  996. } = this.props;
  997. return _desktopSharingEnabled && isScreenAudioSupported();
  998. }
  999. /**
  1000. * Returns true if the desktop sharing button should be visible and
  1001. * false otherwise.
  1002. *
  1003. * @returns {boolean}
  1004. */
  1005. _showDesktopSharingButton() {
  1006. const {
  1007. _desktopSharingEnabled,
  1008. _desktopSharingDisabledTooltipKey
  1009. } = this.props;
  1010. return _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  1011. }
  1012. /**
  1013. * Returns true if the embed meeting button is visible and false otherwise.
  1014. *
  1015. * @returns {boolean}
  1016. */
  1017. _isEmbedMeetingVisible() {
  1018. return !this.props._isVpaasMeeting
  1019. && !this.props._isMobile;
  1020. }
  1021. /**
  1022. * Returns true if the profile button is visible and false otherwise.
  1023. *
  1024. * @returns {boolean}
  1025. */
  1026. _isProfileVisible() {
  1027. return !this.props._isProfileDisabled;
  1028. }
  1029. /**
  1030. * Renders the toolbox content.
  1031. *
  1032. * @returns {ReactElement}
  1033. */
  1034. _renderToolboxContent() {
  1035. const {
  1036. _isMobile,
  1037. _overflowMenuVisible,
  1038. _toolbarButtons,
  1039. showDominantSpeakerName,
  1040. t,
  1041. _reactionsEnabled
  1042. } = this.props;
  1043. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  1044. const containerClassName = `toolbox-content${_isMobile ? ' toolbox-content-mobile' : ''}`;
  1045. const { mainMenuButtons, overflowMenuButtons } = this._getVisibleButtons();
  1046. return (
  1047. <div className = { containerClassName }>
  1048. <div
  1049. className = 'toolbox-content-wrapper'
  1050. onFocus = { this._onTabIn }
  1051. { ...(_isMobile ? {} : {
  1052. onMouseOut: this._onMouseOut,
  1053. onMouseOver: this._onMouseOver
  1054. }) }>
  1055. { showDominantSpeakerName && <DominantSpeakerName /> }
  1056. <div className = 'toolbox-content-items'>
  1057. {mainMenuButtons.map(({ Content, key, ...rest }) => Content !== Separator && (
  1058. <Content
  1059. { ...rest }
  1060. key = { key } />))}
  1061. {Boolean(overflowMenuButtons.length) && (
  1062. <OverflowMenuButton
  1063. ariaControls = 'overflow-menu'
  1064. isOpen = { _overflowMenuVisible }
  1065. key = 'overflow-menu'
  1066. onVisibilityChange = { this._onSetOverflowVisible }
  1067. showMobileReactions = {
  1068. _reactionsEnabled && overflowMenuButtons.find(({ key }) => key === 'raisehand')
  1069. }>
  1070. <ul
  1071. aria-label = { t(toolbarAccLabel) }
  1072. className = 'overflow-menu'
  1073. id = 'overflow-menu'
  1074. onKeyDown = { this._onEscKey }
  1075. role = 'menu'>
  1076. {overflowMenuButtons.map(({ group, key, Content, ...rest }, index, arr) => {
  1077. const showSeparator = index > 0 && arr[index - 1].group !== group;
  1078. return (key !== 'raisehand' || !_reactionsEnabled)
  1079. && <Fragment key = { `f${key}` }>
  1080. {showSeparator && <Separator key = { `hr${group}` } />}
  1081. <Content
  1082. { ...rest }
  1083. key = { key }
  1084. showLabel = { true } />
  1085. </Fragment>
  1086. ;
  1087. })}
  1088. </ul>
  1089. </OverflowMenuButton>
  1090. )}
  1091. <HangupButton
  1092. customClass = 'hangup-button'
  1093. key = 'hangup-button'
  1094. visible = { isToolbarButtonEnabled('hangup', _toolbarButtons) } />
  1095. </div>
  1096. </div>
  1097. </div>
  1098. );
  1099. }
  1100. }
  1101. /**
  1102. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  1103. * props.
  1104. *
  1105. * @param {Object} state - The redux store/state.
  1106. * @param {Object} ownProps - The props explicitly passed.
  1107. * @private
  1108. * @returns {{}}
  1109. */
  1110. function _mapStateToProps(state, ownProps) {
  1111. const { conference } = state['features/base/conference'];
  1112. let desktopSharingEnabled = JitsiMeetJS.isDesktopSharingEnabled();
  1113. const {
  1114. callStatsID,
  1115. disableProfile,
  1116. enableFeaturesBasedOnToken,
  1117. buttonsWithNotifyClick
  1118. } = state['features/base/config'];
  1119. const {
  1120. fullScreen,
  1121. overflowMenuVisible
  1122. } = state['features/toolbox'];
  1123. const localParticipant = getLocalParticipant(state);
  1124. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  1125. const { clientWidth } = state['features/base/responsive-ui'];
  1126. let desktopSharingDisabledTooltipKey;
  1127. if (enableFeaturesBasedOnToken) {
  1128. if (desktopSharingEnabled) {
  1129. // we enable desktop sharing if any participant already have this
  1130. // feature enabled and if the user supports it.
  1131. desktopSharingEnabled = haveParticipantWithScreenSharingFeature(state);
  1132. desktopSharingDisabledTooltipKey = 'dialog.shareYourScreenDisabled';
  1133. }
  1134. }
  1135. let { toolbarButtons } = ownProps;
  1136. const stateToolbarButtons = getToolbarButtons(state);
  1137. if (toolbarButtons) {
  1138. toolbarButtons = toolbarButtons.filter(name => isToolbarButtonEnabled(name, stateToolbarButtons));
  1139. } else {
  1140. toolbarButtons = stateToolbarButtons;
  1141. }
  1142. return {
  1143. _backgroundType: state['features/virtual-background'].backgroundType,
  1144. _buttonsWithNotifyClick: buttonsWithNotifyClick,
  1145. _chatOpen: state['features/chat'].isOpen,
  1146. _clientWidth: clientWidth,
  1147. _conference: conference,
  1148. _desktopSharingEnabled: desktopSharingEnabled,
  1149. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  1150. _dialog: Boolean(state['features/base/dialog'].component),
  1151. _feedbackConfigured: Boolean(callStatsID),
  1152. _fullScreen: fullScreen,
  1153. _isProfileDisabled: Boolean(disableProfile),
  1154. _isMobile: isMobileBrowser(),
  1155. _isVpaasMeeting: isVpaasMeeting(state),
  1156. _localParticipantID: localParticipant?.id,
  1157. _localVideo: localVideo,
  1158. _overflowMenuVisible: overflowMenuVisible,
  1159. _participantsPaneOpen: getParticipantsPaneOpen(state),
  1160. _raisedHand: localParticipant?.raisedHand,
  1161. _reactionsEnabled: isReactionsEnabled(state),
  1162. _screenSharing: isScreenVideoShared(state),
  1163. _tileViewEnabled: shouldDisplayTileView(state),
  1164. _toolbarButtons: toolbarButtons,
  1165. _virtualSource: state['features/virtual-background'].virtualSource,
  1166. _visible: isToolboxVisible(state)
  1167. };
  1168. }
  1169. export default translate(connect(_mapStateToProps)(Toolbox));