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

Toolbox.js 42KB

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