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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  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. const { _dialog, _reactionsEnabled, _participantCount, dispatch, t } = this.props;
  345. if (prevProps._overflowMenuVisible
  346. && !prevProps._dialog
  347. && _dialog) {
  348. this._onSetOverflowVisible(false);
  349. dispatch(setToolbarHovered(false));
  350. }
  351. if (!this.state.reactionsShortcutsRegistered
  352. && (prevProps._reactionsEnabled !== _reactionsEnabled
  353. || prevProps._participantCount !== _participantCount)) {
  354. if (_reactionsEnabled && _participantCount > 1) {
  355. // eslint-disable-next-line react/no-did-update-set-state
  356. this.setState({
  357. reactionsShortcutsRegistered: true
  358. });
  359. const REACTION_SHORTCUTS = Object.keys(REACTIONS).map(key => {
  360. const onShortcutSendReaction = () => {
  361. dispatch(addReactionToBuffer(key));
  362. sendAnalytics(createShortcutEvent(
  363. `reaction.${key}`
  364. ));
  365. };
  366. return {
  367. character: REACTIONS[key].shortcutChar,
  368. exec: onShortcutSendReaction,
  369. helpDescription: t(`toolbar.reaction${key.charAt(0).toUpperCase()}${key.slice(1)}`),
  370. altKey: true
  371. };
  372. });
  373. REACTION_SHORTCUTS.forEach(shortcut => {
  374. APP.keyboardshortcut.registerShortcut(
  375. shortcut.character,
  376. null,
  377. shortcut.exec,
  378. shortcut.helpDescription,
  379. shortcut.altKey);
  380. });
  381. }
  382. }
  383. }
  384. /**
  385. * Removes keyboard shortcuts registered by this component.
  386. *
  387. * @inheritdoc
  388. * @returns {void}
  389. */
  390. componentWillUnmount() {
  391. [ 'A', 'C', 'D', 'R', 'S' ].forEach(letter =>
  392. APP.keyboardshortcut.unregisterShortcut(letter));
  393. if (this.props._reactionsEnabled && this.state.reactionsShortcutsRegistered) {
  394. Object.keys(REACTIONS).map(key => REACTIONS[key].shortcutChar)
  395. .forEach(letter =>
  396. APP.keyboardshortcut.unregisterShortcut(letter, true));
  397. }
  398. }
  399. /**
  400. * Implements React's {@link Component#render()}.
  401. *
  402. * @inheritdoc
  403. * @returns {ReactElement}
  404. */
  405. render() {
  406. const { _chatOpen, _visible, _toolbarButtons } = this.props;
  407. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  408. _toolbarButtons.length ? '' : 'no-buttons'} ${_chatOpen ? 'shift-right' : ''}`;
  409. return (
  410. <div
  411. className = { rootClassNames }
  412. id = 'new-toolbox'>
  413. { this._renderToolboxContent() }
  414. </div>
  415. );
  416. }
  417. _onEscKey: (KeyboardEvent) => void;
  418. /**
  419. * Key handler for overflow menu.
  420. *
  421. * @param {KeyboardEvent} e - Esc key click to close the popup.
  422. * @returns {void}
  423. */
  424. _onEscKey(e) {
  425. if (e.key === 'Escape') {
  426. e.stopPropagation();
  427. this._closeOverflowMenuIfOpen();
  428. }
  429. }
  430. /**
  431. * Closes the overflow menu if opened.
  432. *
  433. * @private
  434. * @returns {void}
  435. */
  436. _closeOverflowMenuIfOpen() {
  437. const { dispatch, _overflowMenuVisible } = this.props;
  438. _overflowMenuVisible && dispatch(setOverflowMenuVisible(false));
  439. }
  440. /**
  441. * Dispatches an action to open the video quality dialog.
  442. *
  443. * @private
  444. * @returns {void}
  445. */
  446. _doOpenVideoQuality() {
  447. this.props.dispatch(openDialog(VideoQualityDialog));
  448. }
  449. /**
  450. * Dispatches an action to toggle the display of chat.
  451. *
  452. * @private
  453. * @returns {void}
  454. */
  455. _doToggleChat() {
  456. this.props.dispatch(toggleChat());
  457. }
  458. /**
  459. * Dispatches an action to toggle screensharing.
  460. *
  461. * @private
  462. * @returns {void}
  463. */
  464. _doToggleFullScreen() {
  465. const fullScreen = !this.props._fullScreen;
  466. this.props.dispatch(setFullScreen(fullScreen));
  467. }
  468. /**
  469. * Dispatches an action to toggle the local participant's raised hand state.
  470. *
  471. * @private
  472. * @returns {void}
  473. */
  474. _doToggleRaiseHand() {
  475. const { _localParticipantID, _raisedHand } = this.props;
  476. const newRaisedStatus = !_raisedHand;
  477. this.props.dispatch(raiseHand(newRaisedStatus));
  478. APP.API.notifyRaiseHandUpdated(_localParticipantID, newRaisedStatus);
  479. }
  480. /**
  481. * Dispatches an action to toggle screensharing.
  482. *
  483. * @private
  484. * @param {boolean} enabled - The state to toggle screen sharing to.
  485. * @param {boolean} audioOnly - Only share system audio.
  486. * @returns {void}
  487. */
  488. _doToggleScreenshare() {
  489. const {
  490. _backgroundType,
  491. _desktopSharingEnabled,
  492. _localVideo,
  493. _virtualSource,
  494. dispatch
  495. } = this.props;
  496. if (_backgroundType === VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE) {
  497. const noneOptions = {
  498. enabled: false,
  499. backgroundType: VIRTUAL_BACKGROUND_TYPE.NONE,
  500. selectedThumbnail: VIRTUAL_BACKGROUND_TYPE.NONE,
  501. backgroundEffectEnabled: false
  502. };
  503. _virtualSource.dispose();
  504. dispatch(toggleBackgroundEffect(noneOptions, _localVideo));
  505. return;
  506. }
  507. if (_desktopSharingEnabled) {
  508. dispatch(startScreenShareFlow());
  509. }
  510. }
  511. /**
  512. * Dispatches an action to toggle the video quality dialog.
  513. *
  514. * @private
  515. * @returns {void}
  516. */
  517. _doToggleVideoQuality() {
  518. this.props.dispatch(toggleDialog(VideoQualityDialog));
  519. }
  520. /**
  521. * Dispaches an action to toggle tile view.
  522. *
  523. * @private
  524. * @returns {void}
  525. */
  526. _doToggleTileView() {
  527. this.props.dispatch(toggleTileView());
  528. }
  529. /**
  530. * Returns all buttons that could be rendered.
  531. *
  532. * @param {Object} state - The redux state.
  533. * @returns {Object} The button maps mainMenuButtons and overflowMenuButtons.
  534. */
  535. _getAllButtons() {
  536. const {
  537. _feedbackConfigured,
  538. _isMobile,
  539. _screenSharing,
  540. _reactionsEnabled
  541. } = this.props;
  542. const microphone = {
  543. key: 'microphone',
  544. Content: AudioSettingsButton,
  545. group: 0
  546. };
  547. const camera = {
  548. key: 'camera',
  549. Content: VideoSettingsButton,
  550. group: 0
  551. };
  552. const profile = this._isProfileVisible() && {
  553. key: 'profile',
  554. Content: ProfileButton,
  555. group: 1
  556. };
  557. const chat = {
  558. key: 'chat',
  559. Content: ChatButton,
  560. handleClick: this._onToolbarToggleChat,
  561. group: 2
  562. };
  563. const desktop = this._showDesktopSharingButton() && {
  564. key: 'desktop',
  565. Content: ShareDesktopButton,
  566. handleClick: this._onToolbarToggleScreenshare,
  567. group: 2
  568. };
  569. const raisehand = {
  570. key: 'raisehand',
  571. Content: _reactionsEnabled ? ReactionsMenuButton : RaiseHandButton,
  572. handleClick: _reactionsEnabled ? null : this._onToolbarToggleRaiseHand,
  573. group: 2
  574. };
  575. const participants = {
  576. key: 'participants-pane',
  577. Content: ParticipantsPaneButton,
  578. handleClick: this._onToolbarToggleParticipantsPane,
  579. group: 2
  580. };
  581. const invite = {
  582. key: 'invite',
  583. Content: InviteButton,
  584. group: 2
  585. };
  586. const tileview = {
  587. key: 'tileview',
  588. Content: TileViewButton,
  589. group: 2
  590. };
  591. const toggleCamera = {
  592. key: 'toggle-camera',
  593. Content: ToggleCameraButton,
  594. group: 2
  595. };
  596. const videoQuality = {
  597. key: 'videoquality',
  598. Content: VideoQualityButton,
  599. handleClick: this._onToolbarOpenVideoQuality,
  600. group: 2
  601. };
  602. const fullscreen = !_isMobile && {
  603. key: 'fullscreen',
  604. Content: FullscreenButton,
  605. handleClick: this._onToolbarToggleFullScreen,
  606. group: 2
  607. };
  608. const security = {
  609. key: 'security',
  610. alias: 'info',
  611. Content: SecurityDialogButton,
  612. group: 2
  613. };
  614. const cc = {
  615. key: 'closedcaptions',
  616. Content: ClosedCaptionButton,
  617. group: 2
  618. };
  619. const recording = {
  620. key: 'recording',
  621. Content: RecordButton,
  622. group: 2
  623. };
  624. const localRecording = {
  625. key: 'localrecording',
  626. Content: LocalRecordingButton,
  627. group: 2
  628. };
  629. const livestreaming = {
  630. key: 'livestreaming',
  631. Content: LiveStreamButton,
  632. group: 2
  633. };
  634. const muteEveryone = {
  635. key: 'mute-everyone',
  636. Content: MuteEveryoneButton,
  637. group: 2
  638. };
  639. const muteVideoEveryone = {
  640. key: 'mute-video-everyone',
  641. Content: MuteEveryonesVideoButton,
  642. group: 2
  643. };
  644. const shareVideo = {
  645. key: 'sharedvideo',
  646. Content: SharedVideoButton,
  647. group: 3
  648. };
  649. const shareAudio = this._showAudioSharingButton() && {
  650. key: 'shareaudio',
  651. Content: ShareAudioButton,
  652. group: 3
  653. };
  654. const etherpad = {
  655. key: 'etherpad',
  656. Content: SharedDocumentButton,
  657. group: 3
  658. };
  659. const virtualBackground = !_screenSharing && {
  660. key: 'select-background',
  661. Content: VideoBackgroundButton,
  662. group: 3
  663. };
  664. const speakerStats = {
  665. key: 'stats',
  666. Content: SpeakerStatsButton,
  667. group: 3
  668. };
  669. const settings = {
  670. key: 'settings',
  671. Content: SettingsButton,
  672. group: 4
  673. };
  674. const shortcuts = !_isMobile && keyboardShortcut.getEnabled() && {
  675. key: 'shortcuts',
  676. Content: KeyboardShortcutsButton,
  677. group: 4
  678. };
  679. const embed = this._isEmbedMeetingVisible() && {
  680. key: 'embedmeeting',
  681. Content: EmbedMeetingButton,
  682. group: 4
  683. };
  684. const feedback = _feedbackConfigured && {
  685. key: 'feedback',
  686. Content: FeedbackButton,
  687. group: 4
  688. };
  689. const download = {
  690. key: 'download',
  691. Content: DownloadButton,
  692. group: 4
  693. };
  694. const help = {
  695. key: 'help',
  696. Content: HelpButton,
  697. group: 4
  698. };
  699. return {
  700. microphone,
  701. camera,
  702. profile,
  703. desktop,
  704. chat,
  705. raisehand,
  706. participants,
  707. invite,
  708. tileview,
  709. toggleCamera,
  710. videoQuality,
  711. fullscreen,
  712. security,
  713. cc,
  714. recording,
  715. localRecording,
  716. livestreaming,
  717. muteEveryone,
  718. muteVideoEveryone,
  719. shareVideo,
  720. shareAudio,
  721. etherpad,
  722. virtualBackground,
  723. speakerStats,
  724. settings,
  725. shortcuts,
  726. embed,
  727. feedback,
  728. download,
  729. help
  730. };
  731. }
  732. /**
  733. * Overwrites click handlers for buttons in case click is exposed through the iframe API.
  734. *
  735. * @param {Object} buttons - The list of toolbar buttons.
  736. * @returns {void}
  737. */
  738. _overwriteButtonsClickHandlers(buttons) {
  739. if (typeof APP === 'undefined' || !this.props._buttonsWithNotifyClick?.length) {
  740. return;
  741. }
  742. Object.values(buttons).forEach((button: any) => {
  743. if (this.props._buttonsWithNotifyClick.includes(button.key)) {
  744. button.handleClick = () => APP.API.notifyToolbarButtonClicked(button.key);
  745. }
  746. });
  747. }
  748. /**
  749. * Returns all buttons that need to be rendered.
  750. *
  751. * @param {Object} state - The redux state.
  752. * @returns {Object} The visible buttons arrays .
  753. */
  754. _getVisibleButtons() {
  755. const {
  756. _clientWidth,
  757. _toolbarButtons
  758. } = this.props;
  759. const buttons = this._getAllButtons();
  760. this._overwriteButtonsClickHandlers(buttons);
  761. const isHangupVisible = isToolbarButtonEnabled('hangup', _toolbarButtons);
  762. const { order } = THRESHOLDS.find(({ width }) => _clientWidth > width)
  763. || THRESHOLDS[THRESHOLDS.length - 1];
  764. let sliceIndex = order.length + 2;
  765. const keys = Object.keys(buttons);
  766. const filtered = [
  767. ...order.map(key => buttons[key]),
  768. ...Object.values(buttons).filter((button, index) => !order.includes(keys[index]))
  769. ].filter(Boolean).filter(({ key, alias = NOT_APPLICABLE }) =>
  770. isToolbarButtonEnabled(key, _toolbarButtons) || isToolbarButtonEnabled(alias, _toolbarButtons));
  771. if (isHangupVisible) {
  772. sliceIndex -= 1;
  773. }
  774. // This implies that the overflow button will be displayed, so save some space for it.
  775. if (sliceIndex < filtered.length) {
  776. sliceIndex -= 1;
  777. }
  778. return {
  779. mainMenuButtons: filtered.slice(0, sliceIndex),
  780. overflowMenuButtons: filtered.slice(sliceIndex)
  781. };
  782. }
  783. _onMouseOut: () => void;
  784. /**
  785. * Dispatches an action signaling the toolbar is not being hovered.
  786. *
  787. * @private
  788. * @returns {void}
  789. */
  790. _onMouseOut() {
  791. const { _overflowMenuVisible, dispatch } = this.props;
  792. !_overflowMenuVisible && dispatch(setToolbarHovered(false));
  793. }
  794. _onMouseOver: () => void;
  795. /**
  796. * Dispatches an action signaling the toolbar is being hovered.
  797. *
  798. * @private
  799. * @returns {void}
  800. */
  801. _onMouseOver() {
  802. this.props.dispatch(setToolbarHovered(true));
  803. }
  804. _onSetOverflowVisible: (boolean) => void;
  805. /**
  806. * Sets the visibility of the overflow menu.
  807. *
  808. * @param {boolean} visible - Whether or not the overflow menu should be
  809. * displayed.
  810. * @private
  811. * @returns {void}
  812. */
  813. _onSetOverflowVisible(visible) {
  814. this.props.dispatch(setOverflowMenuVisible(visible));
  815. this.props.dispatch(setToolbarHovered(visible));
  816. }
  817. _onShortcutToggleChat: () => void;
  818. /**
  819. * Creates an analytics keyboard shortcut event and dispatches an action for
  820. * toggling the display of chat.
  821. *
  822. * @private
  823. * @returns {void}
  824. */
  825. _onShortcutToggleChat() {
  826. sendAnalytics(createShortcutEvent(
  827. 'toggle.chat',
  828. {
  829. enable: !this.props._chatOpen
  830. }));
  831. // Checks if there was any text selected by the user.
  832. // Used for when we press simultaneously keys for copying
  833. // text messages from the chat board
  834. if (window.getSelection().toString() !== '') {
  835. return false;
  836. }
  837. this._doToggleChat();
  838. }
  839. _onShortcutToggleParticipantsPane: () => void;
  840. /**
  841. * Creates an analytics keyboard shortcut event and dispatches an action for
  842. * toggling the display of the participants pane.
  843. *
  844. * @private
  845. * @returns {void}
  846. */
  847. _onShortcutToggleParticipantsPane() {
  848. sendAnalytics(createShortcutEvent(
  849. 'toggle.participants-pane',
  850. {
  851. enable: !this.props._participantsPaneOpen
  852. }));
  853. this._onToolbarToggleParticipantsPane();
  854. }
  855. _onShortcutToggleVideoQuality: () => void;
  856. /**
  857. * Creates an analytics keyboard shortcut event and dispatches an action for
  858. * toggling the display of Video Quality.
  859. *
  860. * @private
  861. * @returns {void}
  862. */
  863. _onShortcutToggleVideoQuality() {
  864. sendAnalytics(createShortcutEvent('video.quality'));
  865. this._doToggleVideoQuality();
  866. }
  867. _onShortcutToggleTileView: () => void;
  868. /**
  869. * Dispatches an action for toggling the tile view.
  870. *
  871. * @private
  872. * @returns {void}
  873. */
  874. _onShortcutToggleTileView() {
  875. sendAnalytics(createShortcutEvent(
  876. 'toggle.tileview',
  877. {
  878. enable: !this.props._tileViewEnabled
  879. }));
  880. this._doToggleTileView();
  881. }
  882. _onShortcutToggleFullScreen: () => void;
  883. /**
  884. * Creates an analytics keyboard shortcut event and dispatches an action for
  885. * toggling full screen mode.
  886. *
  887. * @private
  888. * @returns {void}
  889. */
  890. _onShortcutToggleFullScreen() {
  891. sendAnalytics(createShortcutEvent(
  892. 'toggle.fullscreen',
  893. {
  894. enable: !this.props._fullScreen
  895. }));
  896. this._doToggleFullScreen();
  897. }
  898. _onShortcutToggleRaiseHand: () => void;
  899. /**
  900. * Creates an analytics keyboard shortcut event and dispatches an action for
  901. * toggling raise hand.
  902. *
  903. * @private
  904. * @returns {void}
  905. */
  906. _onShortcutToggleRaiseHand() {
  907. sendAnalytics(createShortcutEvent(
  908. 'toggle.raise.hand',
  909. ACTION_SHORTCUT_TRIGGERED,
  910. { enable: !this.props._raisedHand }));
  911. this._doToggleRaiseHand();
  912. }
  913. _onShortcutToggleScreenshare: () => void;
  914. /**
  915. * Creates an analytics keyboard shortcut event and dispatches an action for
  916. * toggling screensharing.
  917. *
  918. * @private
  919. * @returns {void}
  920. */
  921. _onShortcutToggleScreenshare() {
  922. sendAnalytics(createShortcutEvent(
  923. 'toggle.screen.sharing',
  924. ACTION_SHORTCUT_TRIGGERED,
  925. {
  926. enable: !this.props._screenSharing
  927. }));
  928. this._doToggleScreenshare();
  929. }
  930. _onTabIn: () => void;
  931. /**
  932. * Toggle the toolbar visibility when tabbing into it.
  933. *
  934. * @returns {void}
  935. */
  936. _onTabIn() {
  937. if (!this.props._visible) {
  938. this.props.dispatch(showToolbox());
  939. }
  940. }
  941. _onToolbarToggleParticipantsPane: () => void;
  942. /**
  943. * Dispatches an action for toggling the participants pane.
  944. *
  945. * @private
  946. * @returns {void}
  947. */
  948. _onToolbarToggleParticipantsPane() {
  949. const { dispatch, _participantsPaneOpen } = this.props;
  950. if (_participantsPaneOpen) {
  951. dispatch(closeParticipantsPane());
  952. } else {
  953. dispatch(openParticipantsPane());
  954. }
  955. }
  956. _onToolbarOpenVideoQuality: () => void;
  957. /**
  958. * Creates an analytics toolbar event and dispatches an action for toggling
  959. * open the video quality dialog.
  960. *
  961. * @private
  962. * @returns {void}
  963. */
  964. _onToolbarOpenVideoQuality() {
  965. sendAnalytics(createToolbarEvent('video.quality'));
  966. this._doOpenVideoQuality();
  967. }
  968. _onToolbarToggleChat: () => void;
  969. /**
  970. * Creates an analytics toolbar event and dispatches an action for toggling
  971. * the display of chat.
  972. *
  973. * @private
  974. * @returns {void}
  975. */
  976. _onToolbarToggleChat() {
  977. sendAnalytics(createToolbarEvent(
  978. 'toggle.chat',
  979. {
  980. enable: !this.props._chatOpen
  981. }));
  982. this._closeOverflowMenuIfOpen();
  983. this._doToggleChat();
  984. }
  985. _onToolbarToggleFullScreen: () => void;
  986. /**
  987. * Creates an analytics toolbar event and dispatches an action for toggling
  988. * full screen mode.
  989. *
  990. * @private
  991. * @returns {void}
  992. */
  993. _onToolbarToggleFullScreen() {
  994. sendAnalytics(createToolbarEvent(
  995. 'toggle.fullscreen',
  996. {
  997. enable: !this.props._fullScreen
  998. }));
  999. this._closeOverflowMenuIfOpen();
  1000. this._doToggleFullScreen();
  1001. }
  1002. _onToolbarToggleRaiseHand: () => void;
  1003. /**
  1004. * Creates an analytics toolbar event and dispatches an action for toggling
  1005. * raise hand.
  1006. *
  1007. * @private
  1008. * @returns {void}
  1009. */
  1010. _onToolbarToggleRaiseHand() {
  1011. sendAnalytics(createToolbarEvent(
  1012. 'raise.hand',
  1013. { enable: !this.props._raisedHand }));
  1014. this._doToggleRaiseHand();
  1015. }
  1016. _onToolbarToggleScreenshare: () => void;
  1017. /**
  1018. * Creates an analytics toolbar event and dispatches an action for toggling
  1019. * screensharing.
  1020. *
  1021. * @private
  1022. * @returns {void}
  1023. */
  1024. _onToolbarToggleScreenshare() {
  1025. sendAnalytics(createToolbarEvent(
  1026. 'toggle.screen.sharing',
  1027. ACTION_SHORTCUT_TRIGGERED,
  1028. { enable: !this.props._screenSharing }));
  1029. this._closeOverflowMenuIfOpen();
  1030. this._doToggleScreenshare();
  1031. }
  1032. /**
  1033. * Returns true if the audio sharing button should be visible and
  1034. * false otherwise.
  1035. *
  1036. * @returns {boolean}
  1037. */
  1038. _showAudioSharingButton() {
  1039. const {
  1040. _desktopSharingEnabled
  1041. } = this.props;
  1042. return _desktopSharingEnabled && isScreenAudioSupported();
  1043. }
  1044. /**
  1045. * Returns true if the desktop sharing button should be visible and
  1046. * false otherwise.
  1047. *
  1048. * @returns {boolean}
  1049. */
  1050. _showDesktopSharingButton() {
  1051. const {
  1052. _desktopSharingEnabled,
  1053. _desktopSharingDisabledTooltipKey
  1054. } = this.props;
  1055. return _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  1056. }
  1057. /**
  1058. * Returns true if the embed meeting button is visible and false otherwise.
  1059. *
  1060. * @returns {boolean}
  1061. */
  1062. _isEmbedMeetingVisible() {
  1063. return !this.props._isVpaasMeeting
  1064. && !this.props._isMobile;
  1065. }
  1066. /**
  1067. * Returns true if the profile button is visible and false otherwise.
  1068. *
  1069. * @returns {boolean}
  1070. */
  1071. _isProfileVisible() {
  1072. return !this.props._isProfileDisabled;
  1073. }
  1074. /**
  1075. * Renders the toolbox content.
  1076. *
  1077. * @returns {ReactElement}
  1078. */
  1079. _renderToolboxContent() {
  1080. const {
  1081. _isMobile,
  1082. _overflowMenuVisible,
  1083. _toolbarButtons,
  1084. showDominantSpeakerName,
  1085. t,
  1086. _reactionsEnabled
  1087. } = this.props;
  1088. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  1089. const containerClassName = `toolbox-content${_isMobile ? ' toolbox-content-mobile' : ''}`;
  1090. const { mainMenuButtons, overflowMenuButtons } = this._getVisibleButtons();
  1091. return (
  1092. <div className = { containerClassName }>
  1093. <div
  1094. className = 'toolbox-content-wrapper'
  1095. onFocus = { this._onTabIn }
  1096. { ...(_isMobile ? {} : {
  1097. onMouseOut: this._onMouseOut,
  1098. onMouseOver: this._onMouseOver
  1099. }) }>
  1100. { showDominantSpeakerName && <DominantSpeakerName /> }
  1101. <div className = 'toolbox-content-items'>
  1102. {mainMenuButtons.map(({ Content, key, ...rest }) => Content !== Separator && (
  1103. <Content
  1104. { ...rest }
  1105. key = { key } />))}
  1106. {Boolean(overflowMenuButtons.length) && (
  1107. <OverflowMenuButton
  1108. ariaControls = 'overflow-menu'
  1109. isOpen = { _overflowMenuVisible }
  1110. key = 'overflow-menu'
  1111. onVisibilityChange = { this._onSetOverflowVisible }
  1112. showMobileReactions = {
  1113. _reactionsEnabled && overflowMenuButtons.find(({ key }) => key === 'raisehand')
  1114. }>
  1115. <ul
  1116. aria-label = { t(toolbarAccLabel) }
  1117. className = 'overflow-menu'
  1118. id = 'overflow-menu'
  1119. onKeyDown = { this._onEscKey }
  1120. role = 'menu'>
  1121. {overflowMenuButtons.map(({ group, key, Content, ...rest }, index, arr) => {
  1122. const showSeparator = index > 0 && arr[index - 1].group !== group;
  1123. return (key !== 'raisehand' || !_reactionsEnabled)
  1124. && <Fragment key = { `f${key}` }>
  1125. {showSeparator && <Separator key = { `hr${group}` } />}
  1126. <Content
  1127. { ...rest }
  1128. key = { key }
  1129. showLabel = { true } />
  1130. </Fragment>
  1131. ;
  1132. })}
  1133. </ul>
  1134. </OverflowMenuButton>
  1135. )}
  1136. <HangupButton
  1137. customClass = 'hangup-button'
  1138. key = 'hangup-button'
  1139. visible = { isToolbarButtonEnabled('hangup', _toolbarButtons) } />
  1140. </div>
  1141. </div>
  1142. </div>
  1143. );
  1144. }
  1145. }
  1146. /**
  1147. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  1148. * props.
  1149. *
  1150. * @param {Object} state - The redux store/state.
  1151. * @param {Object} ownProps - The props explicitly passed.
  1152. * @private
  1153. * @returns {{}}
  1154. */
  1155. function _mapStateToProps(state, ownProps) {
  1156. const { conference } = state['features/base/conference'];
  1157. let desktopSharingEnabled = JitsiMeetJS.isDesktopSharingEnabled();
  1158. const {
  1159. callStatsID,
  1160. disableProfile,
  1161. enableFeaturesBasedOnToken,
  1162. buttonsWithNotifyClick
  1163. } = state['features/base/config'];
  1164. const {
  1165. fullScreen,
  1166. overflowMenuVisible
  1167. } = state['features/toolbox'];
  1168. const localParticipant = getLocalParticipant(state);
  1169. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  1170. const { clientWidth } = state['features/base/responsive-ui'];
  1171. let desktopSharingDisabledTooltipKey;
  1172. if (enableFeaturesBasedOnToken) {
  1173. if (desktopSharingEnabled) {
  1174. // we enable desktop sharing if any participant already have this
  1175. // feature enabled and if the user supports it.
  1176. desktopSharingEnabled = haveParticipantWithScreenSharingFeature(state);
  1177. desktopSharingDisabledTooltipKey = 'dialog.shareYourScreenDisabled';
  1178. }
  1179. }
  1180. let { toolbarButtons } = ownProps;
  1181. const stateToolbarButtons = getToolbarButtons(state);
  1182. if (toolbarButtons) {
  1183. toolbarButtons = toolbarButtons.filter(name => isToolbarButtonEnabled(name, stateToolbarButtons));
  1184. } else {
  1185. toolbarButtons = stateToolbarButtons;
  1186. }
  1187. return {
  1188. _backgroundType: state['features/virtual-background'].backgroundType,
  1189. _buttonsWithNotifyClick: buttonsWithNotifyClick,
  1190. _chatOpen: state['features/chat'].isOpen,
  1191. _clientWidth: clientWidth,
  1192. _conference: conference,
  1193. _desktopSharingEnabled: desktopSharingEnabled,
  1194. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  1195. _dialog: Boolean(state['features/base/dialog'].component),
  1196. _feedbackConfigured: Boolean(callStatsID),
  1197. _fullScreen: fullScreen,
  1198. _isProfileDisabled: Boolean(disableProfile),
  1199. _isMobile: isMobileBrowser(),
  1200. _isVpaasMeeting: isVpaasMeeting(state),
  1201. _localParticipantID: localParticipant?.id,
  1202. _localVideo: localVideo,
  1203. _overflowMenuVisible: overflowMenuVisible,
  1204. _participantCount: getParticipantCount(state),
  1205. _participantsPaneOpen: getParticipantsPaneOpen(state),
  1206. _raisedHand: localParticipant?.raisedHand,
  1207. _reactionsEnabled: isReactionsEnabled(state),
  1208. _screenSharing: isScreenVideoShared(state),
  1209. _tileViewEnabled: shouldDisplayTileView(state),
  1210. _toolbarButtons: toolbarButtons,
  1211. _virtualSource: state['features/virtual-background'].virtualSource,
  1212. _visible: isToolboxVisible(state)
  1213. };
  1214. }
  1215. export default translate(connect(_mapStateToProps)(Toolbox));