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

Toolbox.js 37KB

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