您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbox.js 41KB

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