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

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