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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. // @flow
  2. import React, { Component } from 'react';
  3. import {
  4. ACTION_SHORTCUT_TRIGGERED,
  5. createShortcutEvent,
  6. createToolbarEvent,
  7. sendAnalytics
  8. } from '../../../analytics';
  9. import { openDialog, toggleDialog } from '../../../base/dialog';
  10. import { translate } from '../../../base/i18n';
  11. import {
  12. IconChat,
  13. IconExitFullScreen,
  14. IconFeedback,
  15. IconFullScreen,
  16. IconInvite,
  17. IconOpenInNew,
  18. IconPresentation,
  19. IconRaisedHand,
  20. IconRec,
  21. IconShareDesktop,
  22. IconShareVideo
  23. } from '../../../base/icons';
  24. import {
  25. getLocalParticipant,
  26. getParticipants,
  27. participantUpdated
  28. } from '../../../base/participants';
  29. import { connect, equals } from '../../../base/redux';
  30. import { OverflowMenuItem } from '../../../base/toolbox';
  31. import { getLocalVideoTrack, toggleScreensharing } from '../../../base/tracks';
  32. import { VideoBlurButton } from '../../../blur';
  33. import { ChatCounter, toggleChat } from '../../../chat';
  34. import { E2EEButton } from '../../../e2ee';
  35. import { SharedDocumentButton } from '../../../etherpad';
  36. import { openFeedbackDialog } from '../../../feedback';
  37. import {
  38. beginAddPeople,
  39. InfoDialogButton,
  40. isAddPeopleEnabled,
  41. isDialOutEnabled
  42. } from '../../../invite';
  43. import { openKeyboardShortcutsDialog } from '../../../keyboard-shortcuts';
  44. import {
  45. LocalRecordingButton,
  46. LocalRecordingInfoDialog
  47. } from '../../../local-recording';
  48. import {
  49. LiveStreamButton,
  50. RecordButton
  51. } from '../../../recording';
  52. import {
  53. SETTINGS_TABS,
  54. SettingsButton,
  55. openSettingsDialog
  56. } from '../../../settings';
  57. import { toggleSharedVideo } from '../../../shared-video';
  58. import { SpeakerStats } from '../../../speaker-stats';
  59. import {
  60. TileViewButton,
  61. toggleTileView
  62. } from '../../../video-layout';
  63. import {
  64. OverflowMenuVideoQualityItem,
  65. VideoQualityDialog
  66. } from '../../../video-quality';
  67. import {
  68. setFullScreen,
  69. setOverflowMenuVisible,
  70. setToolbarHovered
  71. } from '../../actions';
  72. import AudioSettingsButton from './AudioSettingsButton';
  73. import DownloadButton from '../DownloadButton';
  74. import { isToolboxVisible } from '../../functions';
  75. import HangupButton from '../HangupButton';
  76. import HelpButton from '../HelpButton';
  77. import OverflowMenuButton from './OverflowMenuButton';
  78. import OverflowMenuProfileItem from './OverflowMenuProfileItem';
  79. import MuteEveryoneButton from './MuteEveryoneButton';
  80. import ToolbarButton from './ToolbarButton';
  81. import VideoSettingsButton from './VideoSettingsButton';
  82. import {
  83. ClosedCaptionButton
  84. } from '../../../subtitles';
  85. /**
  86. * The type of the React {@code Component} props of {@link Toolbox}.
  87. */
  88. type Props = {
  89. /**
  90. * Whether or not the chat feature is currently displayed.
  91. */
  92. _chatOpen: boolean,
  93. /**
  94. * The {@code JitsiConference} for the current conference.
  95. */
  96. _conference: Object,
  97. /**
  98. * The tooltip key to use when screensharing is disabled. Or undefined
  99. * if non to be shown and the button to be hidden.
  100. */
  101. _desktopSharingDisabledTooltipKey: boolean,
  102. /**
  103. * Whether or not screensharing is initialized.
  104. */
  105. _desktopSharingEnabled: boolean,
  106. /**
  107. * Whether or not a dialog is displayed.
  108. */
  109. _dialog: boolean,
  110. /**
  111. * Whether or not call feedback can be sent.
  112. */
  113. _feedbackConfigured: boolean,
  114. /**
  115. * Whether or not the app is currently in full screen.
  116. */
  117. _fullScreen: boolean,
  118. /**
  119. * Whether or not the tile view is enabled.
  120. */
  121. _tileViewEnabled: boolean,
  122. /**
  123. * Whether or not invite should be hidden, regardless of feature
  124. * availability.
  125. */
  126. _hideInviteButton: boolean,
  127. /**
  128. * Whether or not the current user is logged in through a JWT.
  129. */
  130. _isGuest: boolean,
  131. /**
  132. * The ID of the local participant.
  133. */
  134. _localParticipantID: String,
  135. /**
  136. * The subsection of Redux state for local recording
  137. */
  138. _localRecState: Object,
  139. /**
  140. * Whether or not the overflow menu is visible.
  141. */
  142. _overflowMenuVisible: boolean,
  143. /**
  144. * Whether or not the local participant's hand is raised.
  145. */
  146. _raisedHand: boolean,
  147. /**
  148. * Whether or not the local participant is screensharing.
  149. */
  150. _screensharing: boolean,
  151. /**
  152. * Whether or not the local participant is sharing a YouTube video.
  153. */
  154. _sharingVideo: boolean,
  155. /**
  156. * Flag showing whether toolbar is visible.
  157. */
  158. _visible: boolean,
  159. /**
  160. * Set with the buttons which this Toolbox should display.
  161. */
  162. _visibleButtons: Set<string>,
  163. /**
  164. * Invoked to active other features of the app.
  165. */
  166. dispatch: Function,
  167. /**
  168. * Invoked to obtain translated strings.
  169. */
  170. t: Function
  171. };
  172. /**
  173. * The type of the React {@code Component} state of {@link Toolbox}.
  174. */
  175. type State = {
  176. /**
  177. * The width of the browser's window.
  178. */
  179. windowWidth: number
  180. };
  181. declare var APP: Object;
  182. declare var interfaceConfig: Object;
  183. // XXX: We are not currently using state here, but in the future, when
  184. // interfaceConfig is part of redux we will. This will have to be retrieved from the store.
  185. const visibleButtons = new Set(interfaceConfig.TOOLBAR_BUTTONS);
  186. /**
  187. * Implements the conference toolbox on React/Web.
  188. *
  189. * @extends Component
  190. */
  191. class Toolbox extends Component<Props, State> {
  192. /**
  193. * Initializes a new {@code Toolbox} instance.
  194. *
  195. * @param {Props} props - The read-only React {@code Component} props with
  196. * which the new instance is to be initialized.
  197. */
  198. constructor(props: Props) {
  199. super(props);
  200. // Bind event handlers so they are only bound once per instance.
  201. this._onMouseOut = this._onMouseOut.bind(this);
  202. this._onMouseOver = this._onMouseOver.bind(this);
  203. this._onResize = this._onResize.bind(this);
  204. this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
  205. this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
  206. this._onShortcutToggleFullScreen = this._onShortcutToggleFullScreen.bind(this);
  207. this._onShortcutToggleRaiseHand = this._onShortcutToggleRaiseHand.bind(this);
  208. this._onShortcutToggleScreenshare = this._onShortcutToggleScreenshare.bind(this);
  209. this._onShortcutToggleVideoQuality = this._onShortcutToggleVideoQuality.bind(this);
  210. this._onToolbarOpenFeedback = this._onToolbarOpenFeedback.bind(this);
  211. this._onToolbarOpenInvite = this._onToolbarOpenInvite.bind(this);
  212. this._onToolbarOpenKeyboardShortcuts = this._onToolbarOpenKeyboardShortcuts.bind(this);
  213. this._onToolbarOpenSpeakerStats = this._onToolbarOpenSpeakerStats.bind(this);
  214. this._onToolbarOpenVideoQuality = this._onToolbarOpenVideoQuality.bind(this);
  215. this._onToolbarToggleChat = this._onToolbarToggleChat.bind(this);
  216. this._onToolbarToggleFullScreen = this._onToolbarToggleFullScreen.bind(this);
  217. this._onToolbarToggleProfile = this._onToolbarToggleProfile.bind(this);
  218. this._onToolbarToggleRaiseHand = this._onToolbarToggleRaiseHand.bind(this);
  219. this._onToolbarToggleScreenshare = this._onToolbarToggleScreenshare.bind(this);
  220. this._onToolbarToggleSharedVideo = this._onToolbarToggleSharedVideo.bind(this);
  221. this._onToolbarOpenLocalRecordingInfoDialog = this._onToolbarOpenLocalRecordingInfoDialog.bind(this);
  222. this._onShortcutToggleTileView = this._onShortcutToggleTileView.bind(this);
  223. this.state = {
  224. windowWidth: window.innerWidth
  225. };
  226. }
  227. /**
  228. * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
  229. *
  230. * @inheritdoc
  231. * @returns {void}
  232. */
  233. componentDidMount() {
  234. const KEYBOARD_SHORTCUTS = [
  235. this._shouldShowButton('videoquality') && {
  236. character: 'A',
  237. exec: this._onShortcutToggleVideoQuality,
  238. helpDescription: 'keyboardShortcuts.videoQuality'
  239. },
  240. this._shouldShowButton('chat') && {
  241. character: 'C',
  242. exec: this._onShortcutToggleChat,
  243. helpDescription: 'keyboardShortcuts.toggleChat'
  244. },
  245. this._shouldShowButton('desktop') && {
  246. character: 'D',
  247. exec: this._onShortcutToggleScreenshare,
  248. helpDescription: 'keyboardShortcuts.toggleScreensharing'
  249. },
  250. this._shouldShowButton('raisehand') && {
  251. character: 'R',
  252. exec: this._onShortcutToggleRaiseHand,
  253. helpDescription: 'keyboardShortcuts.raiseHand'
  254. },
  255. this._shouldShowButton('fullscreen') && {
  256. character: 'S',
  257. exec: this._onShortcutToggleFullScreen,
  258. helpDescription: 'keyboardShortcuts.fullScreen'
  259. },
  260. this._shouldShowButton('tileview') && {
  261. character: 'W',
  262. exec: this._onShortcutToggleTileView,
  263. helpDescription: 'toolbar.tileViewToggle'
  264. }
  265. ];
  266. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  267. if (typeof shortcut === 'object') {
  268. APP.keyboardshortcut.registerShortcut(
  269. shortcut.character,
  270. null,
  271. shortcut.exec,
  272. shortcut.helpDescription);
  273. }
  274. });
  275. window.addEventListener('resize', this._onResize);
  276. }
  277. /**
  278. * Update the visibility of the {@code OverflowMenuButton}.
  279. *
  280. * @inheritdoc
  281. */
  282. componentDidUpdate(prevProps) {
  283. // Ensure the dialog is closed when the toolbox becomes hidden.
  284. if (prevProps._overflowMenuVisible && !this.props._visible) {
  285. this._onSetOverflowVisible(false);
  286. }
  287. if (prevProps._overflowMenuVisible
  288. && !prevProps._dialog
  289. && this.props._dialog) {
  290. this._onSetOverflowVisible(false);
  291. this.props.dispatch(setToolbarHovered(false));
  292. }
  293. }
  294. /**
  295. * Removes keyboard shortcuts registered by this component.
  296. *
  297. * @inheritdoc
  298. * @returns {void}
  299. */
  300. componentWillUnmount() {
  301. [ 'A', 'C', 'D', 'R', 'S' ].forEach(letter =>
  302. APP.keyboardshortcut.unregisterShortcut(letter));
  303. window.removeEventListener('resize', this._onResize);
  304. }
  305. /**
  306. * Implements React's {@link Component#render()}.
  307. *
  308. * @inheritdoc
  309. * @returns {ReactElement}
  310. */
  311. render() {
  312. const { _visible, _visibleButtons } = this.props;
  313. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  314. _visibleButtons.size ? '' : 'no-buttons'}`;
  315. return (
  316. <div
  317. className = { rootClassNames }
  318. id = 'new-toolbox'
  319. onMouseOut = { this._onMouseOut }
  320. onMouseOver = { this._onMouseOver }>
  321. <div className = 'toolbox-background' />
  322. { this._renderToolboxContent() }
  323. </div>
  324. );
  325. }
  326. /**
  327. * Callback invoked to display {@code FeedbackDialog}.
  328. *
  329. * @private
  330. * @returns {void}
  331. */
  332. _doOpenFeedback() {
  333. const { _conference } = this.props;
  334. this.props.dispatch(openFeedbackDialog(_conference));
  335. }
  336. /**
  337. * Dispatches an action to display {@code KeyboardShortcuts}.
  338. *
  339. * @private
  340. * @returns {void}
  341. */
  342. _doOpenKeyboardShorcuts() {
  343. this.props.dispatch(openKeyboardShortcutsDialog());
  344. }
  345. /**
  346. * Callback invoked to display {@code SpeakerStats}.
  347. *
  348. * @private
  349. * @returns {void}
  350. */
  351. _doOpenSpeakerStats() {
  352. this.props.dispatch(openDialog(SpeakerStats, {
  353. conference: this.props._conference
  354. }));
  355. }
  356. /**
  357. * Dispatches an action to open the video quality dialog.
  358. *
  359. * @private
  360. * @returns {void}
  361. */
  362. _doOpenVideoQuality() {
  363. this.props.dispatch(openDialog(VideoQualityDialog));
  364. }
  365. /**
  366. * Dispatches an action to toggle the display of chat.
  367. *
  368. * @private
  369. * @returns {void}
  370. */
  371. _doToggleChat() {
  372. this.props.dispatch(toggleChat());
  373. }
  374. /**
  375. * Dispatches an action to toggle screensharing.
  376. *
  377. * @private
  378. * @returns {void}
  379. */
  380. _doToggleFullScreen() {
  381. const fullScreen = !this.props._fullScreen;
  382. this.props.dispatch(setFullScreen(fullScreen));
  383. }
  384. /**
  385. * Dispatches an action to show or hide the profile edit panel.
  386. *
  387. * @private
  388. * @returns {void}
  389. */
  390. _doToggleProfile() {
  391. this.props.dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
  392. }
  393. /**
  394. * Dispatches an action to toggle the local participant's raised hand state.
  395. *
  396. * @private
  397. * @returns {void}
  398. */
  399. _doToggleRaiseHand() {
  400. const { _localParticipantID, _raisedHand } = this.props;
  401. this.props.dispatch(participantUpdated({
  402. // XXX Only the local participant is allowed to update without
  403. // stating the JitsiConference instance (i.e. participant property
  404. // `conference` for a remote participant) because the local
  405. // participant is uniquely identified by the very fact that there is
  406. // only one local participant.
  407. id: _localParticipantID,
  408. local: true,
  409. raisedHand: !_raisedHand
  410. }));
  411. }
  412. /**
  413. * Dispatches an action to toggle screensharing.
  414. *
  415. * @private
  416. * @returns {void}
  417. */
  418. _doToggleScreenshare() {
  419. if (this.props._desktopSharingEnabled) {
  420. this.props.dispatch(toggleScreensharing());
  421. }
  422. }
  423. /**
  424. * Dispatches an action to toggle YouTube video sharing.
  425. *
  426. * @private
  427. * @returns {void}
  428. */
  429. _doToggleSharedVideo() {
  430. this.props.dispatch(toggleSharedVideo());
  431. }
  432. /**
  433. * Dispatches an action to toggle the video quality dialog.
  434. *
  435. * @private
  436. * @returns {void}
  437. */
  438. _doToggleVideoQuality() {
  439. this.props.dispatch(toggleDialog(VideoQualityDialog));
  440. }
  441. /**
  442. * Dispaches an action to toggle tile view.
  443. *
  444. * @private
  445. * @returns {void}
  446. */
  447. _doToggleTileView() {
  448. this.props.dispatch(toggleTileView());
  449. }
  450. _onMouseOut: () => void;
  451. /**
  452. * Dispatches an action signaling the toolbar is not being hovered.
  453. *
  454. * @private
  455. * @returns {void}
  456. */
  457. _onMouseOut() {
  458. this.props.dispatch(setToolbarHovered(false));
  459. }
  460. _onMouseOver: () => void;
  461. /**
  462. * Dispatches an action signaling the toolbar is being hovered.
  463. *
  464. * @private
  465. * @returns {void}
  466. */
  467. _onMouseOver() {
  468. this.props.dispatch(setToolbarHovered(true));
  469. }
  470. _onResize: () => void;
  471. /**
  472. * A window resize handler used to calculate the number of buttons we can
  473. * fit in the toolbar.
  474. *
  475. * @private
  476. * @returns {void}
  477. */
  478. _onResize() {
  479. const width = window.innerWidth;
  480. if (this.state.windowWidth !== width) {
  481. this.setState({ windowWidth: width });
  482. }
  483. }
  484. _onSetOverflowVisible: (boolean) => void;
  485. /**
  486. * Sets the visibility of the overflow menu.
  487. *
  488. * @param {boolean} visible - Whether or not the overflow menu should be
  489. * displayed.
  490. * @private
  491. * @returns {void}
  492. */
  493. _onSetOverflowVisible(visible) {
  494. this.props.dispatch(setOverflowMenuVisible(visible));
  495. }
  496. _onShortcutToggleChat: () => void;
  497. /**
  498. * Creates an analytics keyboard shortcut event and dispatches an action for
  499. * toggling the display of chat.
  500. *
  501. * @private
  502. * @returns {void}
  503. */
  504. _onShortcutToggleChat() {
  505. sendAnalytics(createShortcutEvent(
  506. 'toggle.chat',
  507. {
  508. enable: !this.props._chatOpen
  509. }));
  510. this._doToggleChat();
  511. }
  512. _onShortcutToggleVideoQuality: () => void;
  513. /**
  514. * Creates an analytics keyboard shortcut event and dispatches an action for
  515. * toggling the display of Video Quality.
  516. *
  517. * @private
  518. * @returns {void}
  519. */
  520. _onShortcutToggleVideoQuality() {
  521. sendAnalytics(createShortcutEvent('video.quality'));
  522. this._doToggleVideoQuality();
  523. }
  524. _onShortcutToggleTileView: () => void;
  525. /**
  526. * Dispatches an action for toggling the tile view.
  527. *
  528. * @private
  529. * @returns {void}
  530. */
  531. _onShortcutToggleTileView() {
  532. sendAnalytics(createShortcutEvent(
  533. 'toggle.tileview',
  534. {
  535. enable: !this.props._tileViewEnabled
  536. }));
  537. this._doToggleTileView();
  538. }
  539. _onShortcutToggleFullScreen: () => void;
  540. /**
  541. * Creates an analytics keyboard shortcut event and dispatches an action for
  542. * toggling full screen mode.
  543. *
  544. * @private
  545. * @returns {void}
  546. */
  547. _onShortcutToggleFullScreen() {
  548. sendAnalytics(createShortcutEvent(
  549. 'toggle.fullscreen',
  550. {
  551. enable: !this.props._fullScreen
  552. }));
  553. this._doToggleFullScreen();
  554. }
  555. _onShortcutToggleRaiseHand: () => void;
  556. /**
  557. * Creates an analytics keyboard shortcut event and dispatches an action for
  558. * toggling raise hand.
  559. *
  560. * @private
  561. * @returns {void}
  562. */
  563. _onShortcutToggleRaiseHand() {
  564. sendAnalytics(createShortcutEvent(
  565. 'toggle.raise.hand',
  566. ACTION_SHORTCUT_TRIGGERED,
  567. { enable: !this.props._raisedHand }));
  568. this._doToggleRaiseHand();
  569. }
  570. _onShortcutToggleScreenshare: () => void;
  571. /**
  572. * Creates an analytics keyboard shortcut event and dispatches an action for
  573. * toggling screensharing.
  574. *
  575. * @private
  576. * @returns {void}
  577. */
  578. _onShortcutToggleScreenshare() {
  579. sendAnalytics(createToolbarEvent(
  580. 'screen.sharing',
  581. {
  582. enable: !this.props._screensharing
  583. }));
  584. this._doToggleScreenshare();
  585. }
  586. _onToolbarOpenFeedback: () => void;
  587. /**
  588. * Creates an analytics toolbar event and dispatches an action for toggling
  589. * display of feedback.
  590. *
  591. * @private
  592. * @returns {void}
  593. */
  594. _onToolbarOpenFeedback() {
  595. sendAnalytics(createToolbarEvent('feedback'));
  596. this._doOpenFeedback();
  597. }
  598. _onToolbarOpenInvite: () => void;
  599. /**
  600. * Creates an analytics toolbar event and dispatches an action for opening
  601. * the modal for inviting people directly into the conference.
  602. *
  603. * @private
  604. * @returns {void}
  605. */
  606. _onToolbarOpenInvite() {
  607. sendAnalytics(createToolbarEvent('invite'));
  608. this.props.dispatch(beginAddPeople());
  609. }
  610. _onToolbarOpenKeyboardShortcuts: () => void;
  611. /**
  612. * Creates an analytics toolbar event and dispatches an action for opening
  613. * the modal for showing available keyboard shortcuts.
  614. *
  615. * @private
  616. * @returns {void}
  617. */
  618. _onToolbarOpenKeyboardShortcuts() {
  619. sendAnalytics(createToolbarEvent('shortcuts'));
  620. this._doOpenKeyboardShorcuts();
  621. }
  622. _onToolbarOpenSpeakerStats: () => void;
  623. /**
  624. * Creates an analytics toolbar event and dispatches an action for opening
  625. * the speaker stats modal.
  626. *
  627. * @private
  628. * @returns {void}
  629. */
  630. _onToolbarOpenSpeakerStats() {
  631. sendAnalytics(createToolbarEvent('speaker.stats'));
  632. this._doOpenSpeakerStats();
  633. }
  634. _onToolbarOpenVideoQuality: () => void;
  635. /**
  636. * Creates an analytics toolbar event and dispatches an action for toggling
  637. * open the video quality dialog.
  638. *
  639. * @private
  640. * @returns {void}
  641. */
  642. _onToolbarOpenVideoQuality() {
  643. sendAnalytics(createToolbarEvent('video.quality'));
  644. this._doOpenVideoQuality();
  645. }
  646. _onToolbarToggleChat: () => void;
  647. /**
  648. * Creates an analytics toolbar event and dispatches an action for toggling
  649. * the display of chat.
  650. *
  651. * @private
  652. * @returns {void}
  653. */
  654. _onToolbarToggleChat() {
  655. sendAnalytics(createToolbarEvent(
  656. 'toggle.chat',
  657. {
  658. enable: !this.props._chatOpen
  659. }));
  660. this._doToggleChat();
  661. }
  662. _onToolbarToggleFullScreen: () => void;
  663. /**
  664. * Creates an analytics toolbar event and dispatches an action for toggling
  665. * full screen mode.
  666. *
  667. * @private
  668. * @returns {void}
  669. */
  670. _onToolbarToggleFullScreen() {
  671. sendAnalytics(createToolbarEvent(
  672. 'toggle.fullscreen',
  673. {
  674. enable: !this.props._fullScreen
  675. }));
  676. this._doToggleFullScreen();
  677. }
  678. _onToolbarToggleProfile: () => void;
  679. /**
  680. * Creates an analytics toolbar event and dispatches an action for showing
  681. * or hiding the profile edit panel.
  682. *
  683. * @private
  684. * @returns {void}
  685. */
  686. _onToolbarToggleProfile() {
  687. sendAnalytics(createToolbarEvent('profile'));
  688. this._doToggleProfile();
  689. }
  690. _onToolbarToggleRaiseHand: () => void;
  691. /**
  692. * Creates an analytics toolbar event and dispatches an action for toggling
  693. * raise hand.
  694. *
  695. * @private
  696. * @returns {void}
  697. */
  698. _onToolbarToggleRaiseHand() {
  699. sendAnalytics(createToolbarEvent(
  700. 'raise.hand',
  701. { enable: !this.props._raisedHand }));
  702. this._doToggleRaiseHand();
  703. }
  704. _onToolbarToggleScreenshare: () => void;
  705. /**
  706. * Creates an analytics toolbar event and dispatches an action for toggling
  707. * screensharing.
  708. *
  709. * @private
  710. * @returns {void}
  711. */
  712. _onToolbarToggleScreenshare() {
  713. if (!this.props._desktopSharingEnabled) {
  714. return;
  715. }
  716. sendAnalytics(createShortcutEvent(
  717. 'toggle.screen.sharing',
  718. ACTION_SHORTCUT_TRIGGERED,
  719. { enable: !this.props._screensharing }));
  720. this._doToggleScreenshare();
  721. }
  722. _onToolbarToggleSharedVideo: () => void;
  723. /**
  724. * Creates an analytics toolbar event and dispatches an action for toggling
  725. * the sharing of a YouTube video.
  726. *
  727. * @private
  728. * @returns {void}
  729. */
  730. _onToolbarToggleSharedVideo() {
  731. sendAnalytics(createToolbarEvent('shared.video.toggled',
  732. {
  733. enable: !this.props._sharingVideo
  734. }));
  735. this._doToggleSharedVideo();
  736. }
  737. _onToolbarOpenLocalRecordingInfoDialog: () => void;
  738. /**
  739. * Opens the {@code LocalRecordingInfoDialog}.
  740. *
  741. * @private
  742. * @returns {void}
  743. */
  744. _onToolbarOpenLocalRecordingInfoDialog() {
  745. sendAnalytics(createToolbarEvent('local.recording'));
  746. this.props.dispatch(openDialog(LocalRecordingInfoDialog));
  747. }
  748. /**
  749. * Returns true if the the desktop sharing button should be visible and
  750. * false otherwise.
  751. *
  752. * @returns {boolean}
  753. */
  754. _isDesktopSharingButtonVisible() {
  755. const {
  756. _desktopSharingEnabled,
  757. _desktopSharingDisabledTooltipKey
  758. } = this.props;
  759. return _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  760. }
  761. /**
  762. * Renders a button for toggleing screen sharing.
  763. *
  764. * @private
  765. * @param {boolean} isInOverflowMenu - True if the button is moved to the
  766. * overflow menu.
  767. * @returns {ReactElement|null}
  768. */
  769. _renderDesktopSharingButton(isInOverflowMenu = false) {
  770. const {
  771. _desktopSharingEnabled,
  772. _desktopSharingDisabledTooltipKey,
  773. _screensharing,
  774. t
  775. } = this.props;
  776. if (!this._isDesktopSharingButtonVisible()) {
  777. return null;
  778. }
  779. if (isInOverflowMenu) {
  780. return (
  781. <OverflowMenuItem
  782. accessibilityLabel
  783. = { t('toolbar.accessibilityLabel.shareYourScreen') }
  784. disabled = { _desktopSharingEnabled }
  785. icon = { IconShareDesktop }
  786. iconId = 'share-desktop'
  787. key = 'desktop'
  788. onClick = { this._onToolbarToggleScreenshare }
  789. text = {
  790. t(`toolbar.${
  791. _screensharing
  792. ? 'stopScreenSharing' : 'startScreenSharing'}`
  793. )
  794. } />
  795. );
  796. }
  797. const tooltip = t(
  798. _desktopSharingEnabled
  799. ? 'dialog.shareYourScreen' : _desktopSharingDisabledTooltipKey);
  800. return (
  801. <ToolbarButton
  802. accessibilityLabel
  803. = { t('toolbar.accessibilityLabel.shareYourScreen') }
  804. disabled = { !_desktopSharingEnabled }
  805. icon = { IconShareDesktop }
  806. onClick = { this._onToolbarToggleScreenshare }
  807. toggled = { _screensharing }
  808. tooltip = { tooltip } />
  809. );
  810. }
  811. /**
  812. * Returns true if the profile button is visible and false otherwise.
  813. *
  814. * @returns {boolean}
  815. */
  816. _isProfileVisible() {
  817. return this.props._isGuest && this._shouldShowButton('profile');
  818. }
  819. /**
  820. * Renders the list elements of the overflow menu.
  821. *
  822. * @private
  823. * @returns {Array<ReactElement>}
  824. */
  825. _renderOverflowMenuContent() {
  826. const {
  827. _feedbackConfigured,
  828. _fullScreen,
  829. _screensharing,
  830. _sharingVideo,
  831. t
  832. } = this.props;
  833. return [
  834. this._isProfileVisible()
  835. && <OverflowMenuProfileItem
  836. key = 'profile'
  837. onClick = { this._onToolbarToggleProfile } />,
  838. this._shouldShowButton('videoquality')
  839. && <OverflowMenuVideoQualityItem
  840. key = 'videoquality'
  841. onClick = { this._onToolbarOpenVideoQuality } />,
  842. this._shouldShowButton('fullscreen')
  843. && <OverflowMenuItem
  844. accessibilityLabel = { t('toolbar.accessibilityLabel.fullScreen') }
  845. icon = { _fullScreen ? IconExitFullScreen : IconFullScreen }
  846. key = 'fullscreen'
  847. onClick = { this._onToolbarToggleFullScreen }
  848. text = { _fullScreen ? t('toolbar.exitFullScreen') : t('toolbar.enterFullScreen') } />,
  849. <LiveStreamButton
  850. key = 'livestreaming'
  851. showLabel = { true } />,
  852. <RecordButton
  853. key = 'record'
  854. showLabel = { true } />,
  855. this._shouldShowButton('sharedvideo')
  856. && <OverflowMenuItem
  857. accessibilityLabel = { t('toolbar.accessibilityLabel.sharedvideo') }
  858. icon = { IconShareVideo }
  859. key = 'sharedvideo'
  860. onClick = { this._onToolbarToggleSharedVideo }
  861. text = { _sharingVideo ? t('toolbar.stopSharedVideo') : t('toolbar.sharedvideo') } />,
  862. this._shouldShowButton('etherpad')
  863. && <SharedDocumentButton
  864. key = 'etherpad'
  865. showLabel = { true } />,
  866. <VideoBlurButton
  867. key = 'videobackgroundblur'
  868. showLabel = { true }
  869. visible = { this._shouldShowButton('videobackgroundblur') && !_screensharing } />,
  870. <SettingsButton
  871. key = 'settings'
  872. showLabel = { true }
  873. visible = { this._shouldShowButton('settings') } />,
  874. <MuteEveryoneButton
  875. key = 'mute-everyone'
  876. showLabel = { true }
  877. visible = { this._shouldShowButton('mute-everyone') } />,
  878. this._shouldShowButton('stats')
  879. && <OverflowMenuItem
  880. accessibilityLabel = { t('toolbar.accessibilityLabel.speakerStats') }
  881. icon = { IconPresentation }
  882. key = 'stats'
  883. onClick = { this._onToolbarOpenSpeakerStats }
  884. text = { t('toolbar.speakerStats') } />,
  885. this._shouldShowButton('e2ee')
  886. && <E2EEButton
  887. key = 'e2ee'
  888. showLabel = { true } />,
  889. this._shouldShowButton('feedback')
  890. && _feedbackConfigured
  891. && <OverflowMenuItem
  892. accessibilityLabel = { t('toolbar.accessibilityLabel.feedback') }
  893. icon = { IconFeedback }
  894. key = 'feedback'
  895. onClick = { this._onToolbarOpenFeedback }
  896. text = { t('toolbar.feedback') } />,
  897. this._shouldShowButton('shortcuts')
  898. && <OverflowMenuItem
  899. accessibilityLabel = { t('toolbar.accessibilityLabel.shortcuts') }
  900. icon = { IconOpenInNew }
  901. key = 'shortcuts'
  902. onClick = { this._onToolbarOpenKeyboardShortcuts }
  903. text = { t('toolbar.shortcuts') } />,
  904. this._shouldShowButton('download')
  905. && <DownloadButton
  906. key = 'download'
  907. showLabel = { true } />,
  908. this._shouldShowButton('help')
  909. && <HelpButton
  910. key = 'help'
  911. showLabel = { true } />
  912. ];
  913. }
  914. /**
  915. * Renders a list of buttons that are moved to the overflow menu.
  916. *
  917. * @private
  918. * @param {Array<string>} movedButtons - The names of the buttons to be
  919. * moved.
  920. * @returns {Array<ReactElement>}
  921. */
  922. _renderMovedButtons(movedButtons) {
  923. const {
  924. _chatOpen,
  925. _raisedHand,
  926. t
  927. } = this.props;
  928. return movedButtons.map(buttonName => {
  929. switch (buttonName) {
  930. case 'desktop':
  931. return this._renderDesktopSharingButton(true);
  932. case 'raisehand':
  933. return (
  934. <OverflowMenuItem
  935. accessibilityLabel =
  936. { t('toolbar.accessibilityLabel.raiseHand') }
  937. icon = { IconRaisedHand }
  938. key = 'raisedHand'
  939. onClick = { this._onToolbarToggleRaiseHand }
  940. text = {
  941. t(`toolbar.${
  942. _raisedHand
  943. ? 'lowerYourHand' : 'raiseYourHand'}`
  944. )
  945. } />
  946. );
  947. case 'chat':
  948. return (
  949. <OverflowMenuItem
  950. accessibilityLabel =
  951. { t('toolbar.accessibilityLabel.chat') }
  952. icon = { IconChat }
  953. key = 'chat'
  954. onClick = { this._onToolbarToggleChat }
  955. text = {
  956. t(`toolbar.${
  957. _chatOpen ? 'closeChat' : 'openChat'}`
  958. )
  959. } />
  960. );
  961. case 'closedcaptions':
  962. return <ClosedCaptionButton showLabel = { true } />;
  963. case 'info':
  964. return <InfoDialogButton showLabel = { true } />;
  965. case 'invite':
  966. return (
  967. <OverflowMenuItem
  968. accessibilityLabel = { t('toolbar.accessibilityLabel.invite') }
  969. icon = { IconInvite }
  970. key = 'invite'
  971. onClick = { this._onToolbarOpenInvite }
  972. text = { t('toolbar.invite') } />
  973. );
  974. case 'tileview':
  975. return <TileViewButton showLabel = { true } />;
  976. case 'localrecording':
  977. return (
  978. <OverflowMenuItem
  979. accessibilityLabel = { t('toolbar.accessibilityLabel.localRecording') }
  980. icon = { IconRec }
  981. key = 'localrecording'
  982. onClick = { this._onToolbarOpenLocalRecordingInfoDialog }
  983. text = { t('localRecording.dialogTitle') } />
  984. );
  985. default:
  986. return null;
  987. }
  988. });
  989. }
  990. /**
  991. * Renders the Audio controlling button.
  992. *
  993. * @returns {ReactElement}
  994. */
  995. _renderAudioButton() {
  996. return this._shouldShowButton('microphone')
  997. ? <AudioSettingsButton
  998. key = 'asb'
  999. visible = { true } />
  1000. : null;
  1001. }
  1002. /**
  1003. * Renders the Video controlling button.
  1004. *
  1005. * @returns {ReactElement}
  1006. */
  1007. _renderVideoButton() {
  1008. return this._shouldShowButton('camera')
  1009. ? <VideoSettingsButton
  1010. key = 'vsb'
  1011. visible = { true } />
  1012. : null;
  1013. }
  1014. /**
  1015. * Renders the toolbox content.
  1016. *
  1017. * @returns {Array<ReactElement>}
  1018. */
  1019. _renderToolboxContent() {
  1020. const {
  1021. _chatOpen,
  1022. _hideInviteButton,
  1023. _overflowMenuVisible,
  1024. _raisedHand,
  1025. t
  1026. } = this.props;
  1027. const overflowMenuContent = this._renderOverflowMenuContent();
  1028. const overflowHasItems = Boolean(overflowMenuContent.filter(child => child).length);
  1029. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  1030. const buttonsLeft = [];
  1031. const buttonsRight = [];
  1032. const maxNumberOfButtonsPerGroup = Math.floor(
  1033. (
  1034. this.state.windowWidth
  1035. - 168 // the width of the central group by design
  1036. - 48 // the minimum space between the button groups
  1037. )
  1038. / 56 // the width + padding of a button
  1039. / 2 // divide by the number of groups(left and right group)
  1040. );
  1041. if (this._shouldShowButton('desktop')
  1042. && this._isDesktopSharingButtonVisible()) {
  1043. buttonsLeft.push('desktop');
  1044. }
  1045. if (this._shouldShowButton('raisehand')) {
  1046. buttonsLeft.push('raisehand');
  1047. }
  1048. if (this._shouldShowButton('chat')) {
  1049. buttonsLeft.push('chat');
  1050. }
  1051. if (this._shouldShowButton('closedcaptions')) {
  1052. buttonsLeft.push('closedcaptions');
  1053. }
  1054. if (overflowHasItems) {
  1055. buttonsRight.push('overflowmenu');
  1056. }
  1057. if (this._shouldShowButton('info')) {
  1058. buttonsRight.push('info');
  1059. }
  1060. if (this._shouldShowButton('invite') && !_hideInviteButton) {
  1061. buttonsRight.push('invite');
  1062. }
  1063. if (this._shouldShowButton('tileview')) {
  1064. buttonsRight.push('tileview');
  1065. }
  1066. if (this._shouldShowButton('localrecording')) {
  1067. buttonsRight.push('localrecording');
  1068. }
  1069. const movedButtons = [];
  1070. if (buttonsLeft.length > maxNumberOfButtonsPerGroup) {
  1071. movedButtons.push(...buttonsLeft.splice(
  1072. maxNumberOfButtonsPerGroup,
  1073. buttonsLeft.length - maxNumberOfButtonsPerGroup));
  1074. if (buttonsRight.indexOf('overflowmenu') === -1) {
  1075. buttonsRight.unshift('overflowmenu');
  1076. }
  1077. }
  1078. if (buttonsRight.length > maxNumberOfButtonsPerGroup) {
  1079. if (buttonsRight.indexOf('overflowmenu') === -1) {
  1080. buttonsRight.unshift('overflowmenu');
  1081. }
  1082. let numberOfButtons = maxNumberOfButtonsPerGroup;
  1083. // make sure the more button will be displayed when we move buttons.
  1084. if (numberOfButtons === 0) {
  1085. numberOfButtons++;
  1086. }
  1087. movedButtons.push(...buttonsRight.splice(
  1088. numberOfButtons,
  1089. buttonsRight.length - numberOfButtons));
  1090. }
  1091. overflowMenuContent.splice(
  1092. 1, 0, ...this._renderMovedButtons(movedButtons));
  1093. return (
  1094. <div className = 'toolbox-content'>
  1095. <div className = 'button-group-left'>
  1096. { buttonsLeft.indexOf('desktop') !== -1
  1097. && this._renderDesktopSharingButton() }
  1098. { buttonsLeft.indexOf('raisehand') !== -1
  1099. && <ToolbarButton
  1100. accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
  1101. icon = { IconRaisedHand }
  1102. onClick = { this._onToolbarToggleRaiseHand }
  1103. toggled = { _raisedHand }
  1104. tooltip = { t('toolbar.raiseHand') } /> }
  1105. { buttonsLeft.indexOf('chat') !== -1
  1106. && <div className = 'toolbar-button-with-badge'>
  1107. <ToolbarButton
  1108. accessibilityLabel = { t('toolbar.accessibilityLabel.chat') }
  1109. icon = { IconChat }
  1110. onClick = { this._onToolbarToggleChat }
  1111. toggled = { _chatOpen }
  1112. tooltip = { t('toolbar.chat') } />
  1113. <ChatCounter />
  1114. </div> }
  1115. {
  1116. buttonsLeft.indexOf('closedcaptions') !== -1
  1117. && <ClosedCaptionButton />
  1118. }
  1119. </div>
  1120. <div className = 'button-group-center'>
  1121. { this._renderAudioButton() }
  1122. <HangupButton
  1123. visible = { this._shouldShowButton('hangup') } />
  1124. { this._renderVideoButton() }
  1125. </div>
  1126. <div className = 'button-group-right'>
  1127. { buttonsRight.indexOf('localrecording') !== -1
  1128. && <LocalRecordingButton
  1129. onClick = {
  1130. this._onToolbarOpenLocalRecordingInfoDialog
  1131. } />
  1132. }
  1133. { buttonsRight.indexOf('tileview') !== -1
  1134. && <TileViewButton /> }
  1135. { buttonsRight.indexOf('invite') !== -1
  1136. && <ToolbarButton
  1137. accessibilityLabel =
  1138. { t('toolbar.accessibilityLabel.invite') }
  1139. icon = { IconInvite }
  1140. onClick = { this._onToolbarOpenInvite }
  1141. tooltip = { t('toolbar.invite') } /> }
  1142. {
  1143. buttonsRight.indexOf('info') !== -1
  1144. && <InfoDialogButton />
  1145. }
  1146. { buttonsRight.indexOf('overflowmenu') !== -1
  1147. && <OverflowMenuButton
  1148. isOpen = { _overflowMenuVisible }
  1149. onVisibilityChange = { this._onSetOverflowVisible }>
  1150. <ul
  1151. aria-label = { t(toolbarAccLabel) }
  1152. className = 'overflow-menu'>
  1153. { overflowMenuContent }
  1154. </ul>
  1155. </OverflowMenuButton> }
  1156. </div>
  1157. </div>);
  1158. }
  1159. _shouldShowButton: (string) => boolean;
  1160. /**
  1161. * Returns if a button name has been explicitly configured to be displayed.
  1162. *
  1163. * @param {string} buttonName - The name of the button, as expected in
  1164. * {@link interfaceConfig}.
  1165. * @private
  1166. * @returns {boolean} True if the button should be displayed.
  1167. */
  1168. _shouldShowButton(buttonName) {
  1169. return this.props._visibleButtons.has(buttonName);
  1170. }
  1171. }
  1172. /**
  1173. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  1174. * props.
  1175. *
  1176. * @param {Object} state - The redux store/state.
  1177. * @private
  1178. * @returns {{}}
  1179. */
  1180. function _mapStateToProps(state) {
  1181. const { conference } = state['features/base/conference'];
  1182. let { desktopSharingEnabled } = state['features/base/conference'];
  1183. const {
  1184. callStatsID,
  1185. enableFeaturesBasedOnToken,
  1186. iAmRecorder
  1187. } = state['features/base/config'];
  1188. const sharedVideoStatus = state['features/shared-video'].status;
  1189. const {
  1190. fullScreen,
  1191. overflowMenuVisible
  1192. } = state['features/toolbox'];
  1193. const localParticipant = getLocalParticipant(state);
  1194. const localRecordingStates = state['features/local-recording'];
  1195. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  1196. const addPeopleEnabled = isAddPeopleEnabled(state);
  1197. const dialOutEnabled = isDialOutEnabled(state);
  1198. let desktopSharingDisabledTooltipKey;
  1199. if (enableFeaturesBasedOnToken) {
  1200. // we enable desktop sharing if any participant already have this
  1201. // feature enabled
  1202. desktopSharingEnabled = getParticipants(state)
  1203. .find(({ features = {} }) =>
  1204. String(features['screen-sharing']) === 'true') !== undefined;
  1205. // we want to show button and tooltip
  1206. if (state['features/base/jwt'].isGuest) {
  1207. desktopSharingDisabledTooltipKey
  1208. = 'dialog.shareYourScreenDisabledForGuest';
  1209. } else {
  1210. desktopSharingDisabledTooltipKey
  1211. = 'dialog.shareYourScreenDisabled';
  1212. }
  1213. }
  1214. // NB: We compute the buttons again here because if URL parameters were used to
  1215. // override them we'd miss it.
  1216. const buttons = new Set(interfaceConfig.TOOLBAR_BUTTONS);
  1217. return {
  1218. _chatOpen: state['features/chat'].isOpen,
  1219. _conference: conference,
  1220. _desktopSharingEnabled: desktopSharingEnabled,
  1221. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  1222. _dialog: Boolean(state['features/base/dialog'].component),
  1223. _feedbackConfigured: Boolean(callStatsID),
  1224. _hideInviteButton:
  1225. iAmRecorder || (!addPeopleEnabled && !dialOutEnabled),
  1226. _isGuest: state['features/base/jwt'].isGuest,
  1227. _fullScreen: fullScreen,
  1228. _tileViewEnabled: state['features/video-layout'].tileViewEnabled,
  1229. _localParticipantID: localParticipant.id,
  1230. _localRecState: localRecordingStates,
  1231. _overflowMenuVisible: overflowMenuVisible,
  1232. _raisedHand: localParticipant.raisedHand,
  1233. _screensharing: localVideo && localVideo.videoType === 'desktop',
  1234. _sharingVideo: sharedVideoStatus === 'playing'
  1235. || sharedVideoStatus === 'start'
  1236. || sharedVideoStatus === 'pause',
  1237. _visible: isToolboxVisible(state),
  1238. _visibleButtons: equals(visibleButtons, buttons) ? visibleButtons : buttons
  1239. };
  1240. }
  1241. export default translate(connect(_mapStateToProps)(Toolbox));