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

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