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

Toolbox.js 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import {
  5. ACTION_SHORTCUT_TRIGGERED,
  6. createShortcutEvent,
  7. createToolbarEvent,
  8. sendAnalytics
  9. } from '../../../analytics';
  10. import { openDialog } from '../../../base/dialog';
  11. import { translate } from '../../../base/i18n';
  12. import {
  13. getLocalParticipant,
  14. getParticipants,
  15. participantUpdated
  16. } from '../../../base/participants';
  17. import { getLocalVideoTrack, toggleScreensharing } from '../../../base/tracks';
  18. import { ChatCounter } from '../../../chat';
  19. import { toggleDocument } from '../../../etherpad';
  20. import { openFeedbackDialog } from '../../../feedback';
  21. import {
  22. beginAddPeople,
  23. InfoDialogButton,
  24. isAddPeopleEnabled,
  25. isDialOutEnabled
  26. } from '../../../invite';
  27. import { openKeyboardShortcutsDialog } from '../../../keyboard-shortcuts';
  28. import {
  29. LiveStreamButton,
  30. RecordButton
  31. } from '../../../recording';
  32. import {
  33. SETTINGS_TABS,
  34. SettingsButton,
  35. openSettingsDialog
  36. } from '../../../settings';
  37. import { toggleSharedVideo } from '../../../shared-video';
  38. import { toggleChat } from '../../../side-panel';
  39. import { SpeakerStats } from '../../../speaker-stats';
  40. import {
  41. OverflowMenuVideoQualityItem,
  42. VideoQualityDialog
  43. } from '../../../video-quality';
  44. import {
  45. setFullScreen,
  46. setOverflowMenuVisible,
  47. setToolbarHovered
  48. } from '../../actions';
  49. import AudioMuteButton from '../AudioMuteButton';
  50. import HangupButton from '../HangupButton';
  51. import OverflowMenuButton from './OverflowMenuButton';
  52. import OverflowMenuItem from './OverflowMenuItem';
  53. import OverflowMenuProfileItem from './OverflowMenuProfileItem';
  54. import ToolbarButton from './ToolbarButton';
  55. import VideoMuteButton from '../VideoMuteButton';
  56. /**
  57. * The type of the React {@code Component} props of {@link Toolbox}.
  58. */
  59. type Props = {
  60. /**
  61. * Whether or not the chat feature is currently displayed.
  62. */
  63. _chatOpen: boolean,
  64. /**
  65. * The {@code JitsiConference} for the current conference.
  66. */
  67. _conference: Object,
  68. /**
  69. * The tooltip key to use when screensharing is disabled. Or undefined
  70. * if non to be shown and the button to be hidden.
  71. */
  72. _desktopSharingDisabledTooltipKey: boolean,
  73. /**
  74. * Whether or not screensharing is initialized.
  75. */
  76. _desktopSharingEnabled: boolean,
  77. /**
  78. * Whether or not a dialog is displayed.
  79. */
  80. _dialog: boolean,
  81. /**
  82. * Whether or not the local participant is currently editing a document.
  83. */
  84. _editingDocument: boolean,
  85. /**
  86. * Whether or not collaborative document editing is enabled.
  87. */
  88. _etherpadInitialized: boolean,
  89. /**
  90. * Whether or not call feedback can be sent.
  91. */
  92. _feedbackConfigured: boolean,
  93. /**
  94. * Whether or not the app is currently in full screen.
  95. */
  96. _fullScreen: boolean,
  97. /**
  98. * Whether or not invite should be hidden, regardless of feature
  99. * availability.
  100. */
  101. _hideInviteButton: boolean,
  102. /**
  103. * Whether or not the current user is logged in through a JWT.
  104. */
  105. _isGuest: boolean,
  106. /**
  107. * The ID of the local participant.
  108. */
  109. _localParticipantID: String,
  110. /**
  111. * Whether or not the overflow menu is visible.
  112. */
  113. _overflowMenuVisible: boolean,
  114. /**
  115. * Whether or not the local participant's hand is raised.
  116. */
  117. _raisedHand: boolean,
  118. /**
  119. * Whether or not the local participant is screensharing.
  120. */
  121. _screensharing: boolean,
  122. /**
  123. * Whether or not the local participant is sharing a YouTube video.
  124. */
  125. _sharingVideo: boolean,
  126. /**
  127. * Flag showing whether toolbar is visible.
  128. */
  129. _visible: boolean,
  130. /**
  131. * Set with the buttons which this Toolbox should display.
  132. */
  133. _visibleButtons: Set<string>,
  134. /**
  135. * Invoked to active other features of the app.
  136. */
  137. dispatch: Function,
  138. /**
  139. * Invoked to obtain translated strings.
  140. */
  141. t: Function
  142. };
  143. declare var APP: Object;
  144. declare var interfaceConfig: Object;
  145. /**
  146. * Implements the conference toolbox on React/Web.
  147. *
  148. * @extends Component
  149. */
  150. class Toolbox extends Component<Props> {
  151. /**
  152. * Initializes a new {@code Toolbox} instance.
  153. *
  154. * @param {Props} props - The read-only React {@code Component} props with
  155. * which the new instance is to be initialized.
  156. */
  157. constructor(props: Props) {
  158. super(props);
  159. // Bind event handlers so they are only bound once per instance.
  160. this._onMouseOut = this._onMouseOut.bind(this);
  161. this._onMouseOver = this._onMouseOver.bind(this);
  162. this._onSetOverflowVisible = this._onSetOverflowVisible.bind(this);
  163. this._onShortcutToggleChat = this._onShortcutToggleChat.bind(this);
  164. this._onShortcutToggleFullScreen
  165. = this._onShortcutToggleFullScreen.bind(this);
  166. this._onShortcutToggleRaiseHand
  167. = this._onShortcutToggleRaiseHand.bind(this);
  168. this._onShortcutToggleScreenshare
  169. = this._onShortcutToggleScreenshare.bind(this);
  170. this._onToolbarOpenFeedback
  171. = this._onToolbarOpenFeedback.bind(this);
  172. this._onToolbarOpenInvite = this._onToolbarOpenInvite.bind(this);
  173. this._onToolbarOpenKeyboardShortcuts
  174. = this._onToolbarOpenKeyboardShortcuts.bind(this);
  175. this._onToolbarOpenSpeakerStats
  176. = this._onToolbarOpenSpeakerStats.bind(this);
  177. this._onToolbarOpenVideoQuality
  178. = this._onToolbarOpenVideoQuality.bind(this);
  179. this._onToolbarToggleChat = this._onToolbarToggleChat.bind(this);
  180. this._onToolbarToggleEtherpad
  181. = this._onToolbarToggleEtherpad.bind(this);
  182. this._onToolbarToggleFullScreen
  183. = this._onToolbarToggleFullScreen.bind(this);
  184. this._onToolbarToggleProfile
  185. = this._onToolbarToggleProfile.bind(this);
  186. this._onToolbarToggleRaiseHand
  187. = this._onToolbarToggleRaiseHand.bind(this);
  188. this._onToolbarToggleScreenshare
  189. = this._onToolbarToggleScreenshare.bind(this);
  190. this._onToolbarToggleSharedVideo
  191. = this._onToolbarToggleSharedVideo.bind(this);
  192. }
  193. /**
  194. * Sets keyboard shortcuts for to trigger ToolbarButtons actions.
  195. *
  196. * @inheritdoc
  197. * @returns {void}
  198. */
  199. componentDidMount() {
  200. const KEYBOARD_SHORTCUTS = [
  201. this._shouldShowButton('chat') && {
  202. character: 'C',
  203. exec: this._onShortcutToggleChat,
  204. helpDescription: 'keyboardShortcuts.toggleChat'
  205. },
  206. this._shouldShowButton('desktop') && {
  207. character: 'D',
  208. exec: this._onShortcutToggleScreenshare,
  209. helpDescription: 'keyboardShortcuts.toggleScreensharing'
  210. },
  211. this._shouldShowButton('raisehand') && {
  212. character: 'R',
  213. exec: this._onShortcutToggleRaiseHand,
  214. helpDescription: 'keyboardShortcuts.raiseHand'
  215. },
  216. this._shouldShowButton('fullscreen') && {
  217. character: 'S',
  218. exec: this._onShortcutToggleFullScreen,
  219. helpDescription: 'keyboardShortcuts.fullScreen'
  220. }
  221. ];
  222. KEYBOARD_SHORTCUTS.forEach(shortcut => {
  223. if (typeof shortcut === 'object') {
  224. APP.keyboardshortcut.registerShortcut(
  225. shortcut.character,
  226. null,
  227. shortcut.exec,
  228. shortcut.helpDescription);
  229. }
  230. });
  231. }
  232. /**
  233. * Update the visibility of the {@code OverflowMenuButton}.
  234. *
  235. * @inheritdoc
  236. */
  237. componentWillReceiveProps(nextProps) {
  238. // Ensure the dialog is closed when the toolbox becomes hidden.
  239. if (this.props._overflowMenuVisible && !nextProps._visible) {
  240. this._onSetOverflowVisible(false);
  241. }
  242. if (this.props._overflowMenuVisible
  243. && !this.props._dialog
  244. && nextProps._dialog) {
  245. this._onSetOverflowVisible(false);
  246. this.props.dispatch(setToolbarHovered(false));
  247. }
  248. }
  249. /**
  250. * Removes keyboard shortcuts registered by this component.
  251. *
  252. * @inheritdoc
  253. * @returns {void}
  254. */
  255. componentWillUnmount() {
  256. [ 'C', 'D', 'R', 'S' ].forEach(letter =>
  257. APP.keyboardshortcut.unregisterShortcut(letter));
  258. }
  259. /**
  260. * Implements React's {@link Component#render()}.
  261. *
  262. * @inheritdoc
  263. * @returns {ReactElement}
  264. */
  265. render() {
  266. const {
  267. _chatOpen,
  268. _hideInviteButton,
  269. _overflowMenuVisible,
  270. _raisedHand,
  271. _visible,
  272. _visibleButtons,
  273. t
  274. } = this.props;
  275. const rootClassNames = `new-toolbox ${_visible ? 'visible' : ''} ${
  276. _visibleButtons.size ? '' : 'no-buttons'}`;
  277. const overflowMenuContent = this._renderOverflowMenuContent();
  278. const overflowHasItems = Boolean(overflowMenuContent.filter(
  279. child => child).length);
  280. const toolbarAccLabel = 'toolbar.accessibilityLabel.moreActionsMenu';
  281. return (
  282. <div
  283. className = { rootClassNames }
  284. id = 'new-toolbox'
  285. onMouseOut = { this._onMouseOut }
  286. onMouseOver = { this._onMouseOver }>
  287. <div className = 'button-group-left'>
  288. { this._shouldShowButton('desktop')
  289. && this._renderDesktopSharingButton() }
  290. { this._shouldShowButton('raisehand')
  291. && <ToolbarButton
  292. accessibilityLabel =
  293. { t('toolbar.accessibilityLabel.raiseHand') }
  294. iconName = { _raisedHand
  295. ? 'icon-raised-hand toggled'
  296. : 'icon-raised-hand' }
  297. onClick = { this._onToolbarToggleRaiseHand }
  298. tooltip = { t('toolbar.raiseHand') } /> }
  299. { this._shouldShowButton('chat')
  300. && <div className = 'toolbar-button-with-badge'>
  301. <ToolbarButton
  302. accessibilityLabel =
  303. { t('toolbar.accessibilityLabel.chat') }
  304. iconName = { _chatOpen
  305. ? 'icon-chat toggled'
  306. : 'icon-chat' }
  307. onClick = { this._onToolbarToggleChat }
  308. tooltip = { t('toolbar.chat') } />
  309. <ChatCounter />
  310. </div> }
  311. </div>
  312. <div className = 'button-group-center'>
  313. <AudioMuteButton
  314. visible = { this._shouldShowButton('microphone') } />
  315. <HangupButton
  316. visible = { this._shouldShowButton('hangup') } />
  317. <VideoMuteButton
  318. visible = { this._shouldShowButton('camera') } />
  319. </div>
  320. <div className = 'button-group-right'>
  321. { this._shouldShowButton('invite')
  322. && !_hideInviteButton
  323. && <ToolbarButton
  324. accessibilityLabel =
  325. { t('toolbar.accessibilityLabel.invite') }
  326. iconName = 'icon-add'
  327. onClick = { this._onToolbarOpenInvite }
  328. tooltip = { t('toolbar.invite') } /> }
  329. { this._shouldShowButton('info') && <InfoDialogButton /> }
  330. { overflowHasItems
  331. && <OverflowMenuButton
  332. isOpen = { _overflowMenuVisible }
  333. onVisibilityChange = { this._onSetOverflowVisible }>
  334. <ul
  335. aria-label = { t(toolbarAccLabel) }
  336. className = 'overflow-menu'>
  337. { overflowMenuContent }
  338. </ul>
  339. </OverflowMenuButton> }
  340. </div>
  341. </div>
  342. );
  343. }
  344. /**
  345. * Callback invoked to display {@code FeedbackDialog}.
  346. *
  347. * @private
  348. * @returns {void}
  349. */
  350. _doOpenFeedback() {
  351. const { _conference } = this.props;
  352. this.props.dispatch(openFeedbackDialog(_conference));
  353. }
  354. /**
  355. * Dispatches an action to display {@code KeyboardShortcuts}.
  356. *
  357. * @private
  358. * @returns {void}
  359. */
  360. _doOpenKeyboardShorcuts() {
  361. this.props.dispatch(openKeyboardShortcutsDialog());
  362. }
  363. /**
  364. * Callback invoked to display {@code SpeakerStats}.
  365. *
  366. * @private
  367. * @returns {void}
  368. */
  369. _doOpenSpeakerStats() {
  370. this.props.dispatch(openDialog(SpeakerStats, {
  371. conference: this.props._conference
  372. }));
  373. }
  374. /**
  375. * Dispatches an action to toggle the video quality dialog.
  376. *
  377. * @private
  378. * @returns {void}
  379. */
  380. _doOpenVideoQuality() {
  381. this.props.dispatch(openDialog(VideoQualityDialog));
  382. }
  383. /**
  384. * Dispatches an action to toggle the display of chat.
  385. *
  386. * @private
  387. * @returns {void}
  388. */
  389. _doToggleChat() {
  390. this.props.dispatch(toggleChat());
  391. }
  392. /**
  393. * Dispatches an action to show or hide document editing.
  394. *
  395. * @private
  396. * @returns {void}
  397. */
  398. _doToggleEtherpad() {
  399. this.props.dispatch(toggleDocument());
  400. }
  401. /**
  402. * Dispatches an action to toggle screensharing.
  403. *
  404. * @private
  405. * @returns {void}
  406. */
  407. _doToggleFullScreen() {
  408. const fullScreen = !this.props._fullScreen;
  409. this.props.dispatch(setFullScreen(fullScreen));
  410. }
  411. /**
  412. * Dispatches an action to show or hide the profile edit panel.
  413. *
  414. * @private
  415. * @returns {void}
  416. */
  417. _doToggleProfile() {
  418. this.props.dispatch(openSettingsDialog(SETTINGS_TABS.PROFILE));
  419. }
  420. /**
  421. * Dispatches an action to toggle the local participant's raised hand state.
  422. *
  423. * @private
  424. * @returns {void}
  425. */
  426. _doToggleRaiseHand() {
  427. const { _localParticipantID, _raisedHand } = this.props;
  428. this.props.dispatch(participantUpdated({
  429. // XXX Only the local participant is allowed to update without
  430. // stating the JitsiConference instance (i.e. participant property
  431. // `conference` for a remote participant) because the local
  432. // participant is uniquely identified by the very fact that there is
  433. // only one local participant.
  434. id: _localParticipantID,
  435. local: true,
  436. raisedHand: !_raisedHand
  437. }));
  438. }
  439. /**
  440. * Dispatches an action to toggle screensharing.
  441. *
  442. * @private
  443. * @returns {void}
  444. */
  445. _doToggleScreenshare() {
  446. if (this.props._desktopSharingEnabled) {
  447. this.props.dispatch(toggleScreensharing());
  448. }
  449. }
  450. /**
  451. * Dispatches an action to toggle YouTube video sharing.
  452. *
  453. * @private
  454. * @returns {void}
  455. */
  456. _doToggleSharedVideo() {
  457. this.props.dispatch(toggleSharedVideo());
  458. }
  459. _onMouseOut: () => void;
  460. /**
  461. * Dispatches an action signaling the toolbar is not being hovered.
  462. *
  463. * @private
  464. * @returns {void}
  465. */
  466. _onMouseOut() {
  467. this.props.dispatch(setToolbarHovered(false));
  468. }
  469. _onMouseOver: () => void;
  470. /**
  471. * Dispatches an action signaling the toolbar is being hovered.
  472. *
  473. * @private
  474. * @returns {void}
  475. */
  476. _onMouseOver() {
  477. this.props.dispatch(setToolbarHovered(true));
  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. _onShortcutToggleFullScreen: () => void;
  508. /**
  509. * Creates an analytics keyboard shortcut event and dispatches an action for
  510. * toggling full screen mode.
  511. *
  512. * @private
  513. * @returns {void}
  514. */
  515. _onShortcutToggleFullScreen() {
  516. sendAnalytics(createShortcutEvent(
  517. 'toggle.fullscreen',
  518. {
  519. enable: !this.props._fullScreen
  520. }));
  521. this._doToggleFullScreen();
  522. }
  523. _onShortcutToggleRaiseHand: () => void;
  524. /**
  525. * Creates an analytics keyboard shortcut event and dispatches an action for
  526. * toggling raise hand.
  527. *
  528. * @private
  529. * @returns {void}
  530. */
  531. _onShortcutToggleRaiseHand() {
  532. sendAnalytics(createShortcutEvent(
  533. 'toggle.raise.hand',
  534. ACTION_SHORTCUT_TRIGGERED,
  535. { enable: !this.props._raisedHand }));
  536. this._doToggleRaiseHand();
  537. }
  538. _onShortcutToggleScreenshare: () => void;
  539. /**
  540. * Creates an analytics keyboard shortcut event and dispatches an action for
  541. * toggling screensharing.
  542. *
  543. * @private
  544. * @returns {void}
  545. */
  546. _onShortcutToggleScreenshare() {
  547. sendAnalytics(createToolbarEvent(
  548. 'screen.sharing',
  549. {
  550. enable: !this.props._screensharing
  551. }));
  552. this._doToggleScreenshare();
  553. }
  554. _onToolbarOpenFeedback: () => void;
  555. /**
  556. * Creates an analytics toolbar event and dispatches an action for toggling
  557. * display of feedback.
  558. *
  559. * @private
  560. * @returns {void}
  561. */
  562. _onToolbarOpenFeedback() {
  563. sendAnalytics(createToolbarEvent('feedback'));
  564. this._doOpenFeedback();
  565. }
  566. _onToolbarOpenInvite: () => void;
  567. /**
  568. * Creates an analytics toolbar event and dispatches an action for opening
  569. * the modal for inviting people directly into the conference.
  570. *
  571. * @private
  572. * @returns {void}
  573. */
  574. _onToolbarOpenInvite() {
  575. sendAnalytics(createToolbarEvent('invite'));
  576. this.props.dispatch(beginAddPeople());
  577. }
  578. _onToolbarOpenKeyboardShortcuts: () => void;
  579. /**
  580. * Creates an analytics toolbar event and dispatches an action for opening
  581. * the modal for showing available keyboard shortcuts.
  582. *
  583. * @private
  584. * @returns {void}
  585. */
  586. _onToolbarOpenKeyboardShortcuts() {
  587. sendAnalytics(createToolbarEvent('shortcuts'));
  588. this._doOpenKeyboardShorcuts();
  589. }
  590. _onToolbarOpenSpeakerStats: () => void;
  591. /**
  592. * Creates an analytics toolbar event and dispatches an action for opening
  593. * the speaker stats modal.
  594. *
  595. * @private
  596. * @returns {void}
  597. */
  598. _onToolbarOpenSpeakerStats() {
  599. sendAnalytics(createToolbarEvent('speaker.stats'));
  600. this._doOpenSpeakerStats();
  601. }
  602. _onToolbarOpenVideoQuality: () => void;
  603. /**
  604. * Creates an analytics toolbar event and dispatches an action for toggling
  605. * open the video quality dialog.
  606. *
  607. * @private
  608. * @returns {void}
  609. */
  610. _onToolbarOpenVideoQuality() {
  611. sendAnalytics(createToolbarEvent('video.quality'));
  612. this._doOpenVideoQuality();
  613. }
  614. _onToolbarToggleChat: () => void;
  615. /**
  616. * Creates an analytics toolbar event and dispatches an action for toggling
  617. * the display of chat.
  618. *
  619. * @private
  620. * @returns {void}
  621. */
  622. _onToolbarToggleChat() {
  623. sendAnalytics(createToolbarEvent(
  624. 'toggle.chat',
  625. {
  626. enable: !this.props._chatOpen
  627. }));
  628. this._doToggleChat();
  629. }
  630. _onToolbarToggleEtherpad: () => void;
  631. /**
  632. * Creates an analytics toolbar event and dispatches an action for toggling
  633. * the display of document editing.
  634. *
  635. * @private
  636. * @returns {void}
  637. */
  638. _onToolbarToggleEtherpad() {
  639. sendAnalytics(createToolbarEvent(
  640. 'toggle.etherpad',
  641. {
  642. enable: !this.props._editingDocument
  643. }));
  644. this._doToggleEtherpad();
  645. }
  646. _onToolbarToggleFullScreen: () => void;
  647. /**
  648. * Creates an analytics toolbar event and dispatches an action for toggling
  649. * full screen mode.
  650. *
  651. * @private
  652. * @returns {void}
  653. */
  654. _onToolbarToggleFullScreen() {
  655. sendAnalytics(createToolbarEvent(
  656. 'toggle.fullscreen',
  657. {
  658. enable: !this.props._fullScreen
  659. }));
  660. this._doToggleFullScreen();
  661. }
  662. _onToolbarToggleProfile: () => void;
  663. /**
  664. * Creates an analytics toolbar event and dispatches an action for showing
  665. * or hiding the profile edit panel.
  666. *
  667. * @private
  668. * @returns {void}
  669. */
  670. _onToolbarToggleProfile() {
  671. sendAnalytics(createToolbarEvent('profile'));
  672. this._doToggleProfile();
  673. }
  674. _onToolbarToggleRaiseHand: () => void;
  675. /**
  676. * Creates an analytics toolbar event and dispatches an action for toggling
  677. * raise hand.
  678. *
  679. * @private
  680. * @returns {void}
  681. */
  682. _onToolbarToggleRaiseHand() {
  683. sendAnalytics(createToolbarEvent(
  684. 'raise.hand',
  685. { enable: !this.props._raisedHand }));
  686. this._doToggleRaiseHand();
  687. }
  688. _onToolbarToggleScreenshare: () => void;
  689. /**
  690. * Creates an analytics toolbar event and dispatches an action for toggling
  691. * screensharing.
  692. *
  693. * @private
  694. * @returns {void}
  695. */
  696. _onToolbarToggleScreenshare() {
  697. if (!this.props._desktopSharingEnabled) {
  698. return;
  699. }
  700. sendAnalytics(createShortcutEvent(
  701. 'toggle.screen.sharing',
  702. ACTION_SHORTCUT_TRIGGERED,
  703. { enable: !this.props._screensharing }));
  704. this._doToggleScreenshare();
  705. }
  706. _onToolbarToggleSharedVideo: () => void;
  707. /**
  708. * Creates an analytics toolbar event and dispatches an action for toggling
  709. * the sharing of a YouTube video.
  710. *
  711. * @private
  712. * @returns {void}
  713. */
  714. _onToolbarToggleSharedVideo() {
  715. sendAnalytics(createToolbarEvent('shared.video.toggled',
  716. {
  717. enable: !this.props._sharingVideo
  718. }));
  719. this._doToggleSharedVideo();
  720. }
  721. /**
  722. * Renders a button for toggleing screen sharing.
  723. *
  724. * @private
  725. * @returns {ReactElement|null}
  726. */
  727. _renderDesktopSharingButton() {
  728. const {
  729. _desktopSharingEnabled,
  730. _desktopSharingDisabledTooltipKey,
  731. _screensharing,
  732. t
  733. } = this.props;
  734. const visible
  735. = _desktopSharingEnabled || _desktopSharingDisabledTooltipKey;
  736. if (!visible) {
  737. return null;
  738. }
  739. const classNames = `icon-share-desktop ${
  740. _screensharing ? 'toggled' : ''} ${
  741. _desktopSharingEnabled ? '' : 'disabled'}`;
  742. const tooltip = t(
  743. _desktopSharingEnabled
  744. ? 'dialog.shareYourScreen' : _desktopSharingDisabledTooltipKey);
  745. return (
  746. <ToolbarButton
  747. accessibilityLabel
  748. = { t('toolbar.accessibilityLabel.shareYourScreen') }
  749. iconName = { classNames }
  750. onClick = { this._onToolbarToggleScreenshare }
  751. tooltip = { tooltip } />
  752. );
  753. }
  754. /**
  755. * Renders the list elements of the overflow menu.
  756. *
  757. * @private
  758. * @returns {Array<ReactElement>}
  759. */
  760. _renderOverflowMenuContent() {
  761. const {
  762. _editingDocument,
  763. _etherpadInitialized,
  764. _feedbackConfigured,
  765. _fullScreen,
  766. _isGuest,
  767. _sharingVideo,
  768. t
  769. } = this.props;
  770. return [
  771. _isGuest
  772. && this._shouldShowButton('profile')
  773. && <OverflowMenuProfileItem
  774. key = 'profile'
  775. onClick = { this._onToolbarToggleProfile } />,
  776. this._shouldShowButton('videoquality')
  777. && <OverflowMenuVideoQualityItem
  778. key = 'videoquality'
  779. onClick = { this._onToolbarOpenVideoQuality } />,
  780. this._shouldShowButton('fullscreen')
  781. && <OverflowMenuItem
  782. accessibilityLabel =
  783. { t('toolbar.accessibilityLabel.fullScreen') }
  784. icon = { _fullScreen
  785. ? 'icon-exit-full-screen'
  786. : 'icon-full-screen' }
  787. key = 'fullscreen'
  788. onClick = { this._onToolbarToggleFullScreen }
  789. text = { _fullScreen
  790. ? t('toolbar.exitFullScreen')
  791. : t('toolbar.enterFullScreen') } />,
  792. <LiveStreamButton
  793. key = 'livestreaming'
  794. showLabel = { true } />,
  795. <RecordButton
  796. key = 'record'
  797. showLabel = { true } />,
  798. this._shouldShowButton('sharedvideo')
  799. && <OverflowMenuItem
  800. accessibilityLabel =
  801. { t('toolbar.accessibilityLabel.sharedvideo') }
  802. icon = 'icon-shared-video'
  803. key = 'sharedvideo'
  804. onClick = { this._onToolbarToggleSharedVideo }
  805. text = { _sharingVideo
  806. ? t('toolbar.stopSharedVideo')
  807. : t('toolbar.sharedvideo') } />,
  808. this._shouldShowButton('etherpad')
  809. && _etherpadInitialized
  810. && <OverflowMenuItem
  811. accessibilityLabel =
  812. { t('toolbar.accessibilityLabel.document') }
  813. icon = 'icon-share-doc'
  814. key = 'etherpad'
  815. onClick = { this._onToolbarToggleEtherpad }
  816. text = { _editingDocument
  817. ? t('toolbar.documentClose')
  818. : t('toolbar.documentOpen') } />,
  819. <SettingsButton
  820. key = 'settings'
  821. showLabel = { true }
  822. visible = { this._shouldShowButton('settings') } />,
  823. this._shouldShowButton('stats')
  824. && <OverflowMenuItem
  825. accessibilityLabel =
  826. { t('toolbar.accessibilityLabel.speakerStats') }
  827. icon = 'icon-presentation'
  828. key = 'stats'
  829. onClick = { this._onToolbarOpenSpeakerStats }
  830. text = { t('toolbar.speakerStats') } />,
  831. this._shouldShowButton('feedback')
  832. && _feedbackConfigured
  833. && <OverflowMenuItem
  834. accessibilityLabel =
  835. { t('toolbar.accessibilityLabel.feedback') }
  836. icon = 'icon-feedback'
  837. key = 'feedback'
  838. onClick = { this._onToolbarOpenFeedback }
  839. text = { t('toolbar.feedback') } />,
  840. this._shouldShowButton('shortcuts')
  841. && <OverflowMenuItem
  842. accessibilityLabel =
  843. { t('toolbar.accessibilityLabel.shortcuts') }
  844. icon = 'icon-open_in_new'
  845. key = 'shortcuts'
  846. onClick = { this._onToolbarOpenKeyboardShortcuts }
  847. text = { t('toolbar.shortcuts') } />
  848. ];
  849. }
  850. _shouldShowButton: (string) => boolean;
  851. /**
  852. * Returns if a button name has been explicitly configured to be displayed.
  853. *
  854. * @param {string} buttonName - The name of the button, as expected in
  855. * {@link intefaceConfig}.
  856. * @private
  857. * @returns {boolean} True if the button should be displayed.
  858. */
  859. _shouldShowButton(buttonName) {
  860. return this.props._visibleButtons.has(buttonName);
  861. }
  862. }
  863. /**
  864. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  865. * props.
  866. *
  867. * @param {Object} state - The redux store/state.
  868. * @private
  869. * @returns {{}}
  870. */
  871. function _mapStateToProps(state) {
  872. const { conference } = state['features/base/conference'];
  873. let { desktopSharingEnabled } = state['features/base/conference'];
  874. const {
  875. callStatsID,
  876. iAmRecorder
  877. } = state['features/base/config'];
  878. const sharedVideoStatus = state['features/shared-video'].status;
  879. const { current } = state['features/side-panel'];
  880. const {
  881. alwaysVisible,
  882. fullScreen,
  883. overflowMenuVisible,
  884. timeoutID,
  885. visible
  886. } = state['features/toolbox'];
  887. const localParticipant = getLocalParticipant(state);
  888. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  889. const addPeopleEnabled = isAddPeopleEnabled(state);
  890. const dialOutEnabled = isDialOutEnabled(state);
  891. let desktopSharingDisabledTooltipKey;
  892. if (state['features/base/config'].enableFeaturesBasedOnToken) {
  893. // we enable desktop sharing if any participant already have this
  894. // feature enabled
  895. desktopSharingEnabled = getParticipants(state)
  896. .find(({ features = {} }) =>
  897. String(features['screen-sharing']) === 'true') !== undefined;
  898. // we want to show button and tooltip
  899. if (state['features/base/jwt'].isGuest) {
  900. desktopSharingDisabledTooltipKey
  901. = 'dialog.shareYourScreenDisabledForGuest';
  902. } else {
  903. desktopSharingDisabledTooltipKey
  904. = 'dialog.shareYourScreenDisabled';
  905. }
  906. }
  907. return {
  908. _chatOpen: current === 'chat_container',
  909. _conference: conference,
  910. _desktopSharingEnabled: desktopSharingEnabled,
  911. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  912. _dialog: Boolean(state['features/base/dialog'].component),
  913. _editingDocument: Boolean(state['features/etherpad'].editing),
  914. _etherpadInitialized: Boolean(state['features/etherpad'].initialized),
  915. _feedbackConfigured: Boolean(callStatsID),
  916. _hideInviteButton:
  917. iAmRecorder || (!addPeopleEnabled && !dialOutEnabled),
  918. _isGuest: state['features/base/jwt'].isGuest,
  919. _fullScreen: fullScreen,
  920. _localParticipantID: localParticipant.id,
  921. _overflowMenuVisible: overflowMenuVisible,
  922. _raisedHand: localParticipant.raisedHand,
  923. _screensharing: localVideo && localVideo.videoType === 'desktop',
  924. _sharingVideo: sharedVideoStatus === 'playing'
  925. || sharedVideoStatus === 'start'
  926. || sharedVideoStatus === 'pause',
  927. _visible: Boolean(timeoutID || visible || alwaysVisible),
  928. // XXX: We are not currently using state here, but in the future, when
  929. // interfaceConfig is part of redux we will.
  930. _visibleButtons: new Set(interfaceConfig.TOOLBAR_BUTTONS)
  931. };
  932. }
  933. export default translate(connect(_mapStateToProps)(Toolbox));