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

Toolbox.js 41KB

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