You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbox.js 39KB

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