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

Toolbox.js 42KB

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