You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbox.js 42KB

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