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

Toolbox.js 40KB

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