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

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