Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ShareDesktopButton.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { connect } from 'react-redux';
  2. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  3. import { sendAnalytics } from '../../../analytics/functions';
  4. import { IReduxState } from '../../../app/types';
  5. import { translate } from '../../../base/i18n/functions';
  6. import { IconScreenshare, IconStopScreenshare } from '../../../base/icons/svg';
  7. import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
  8. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  9. import { startScreenShareFlow } from '../../../screen-share/actions.web';
  10. import { isScreenVideoShared } from '../../../screen-share/functions';
  11. import { closeOverflowMenuIfOpen } from '../../actions.web';
  12. import { isDesktopShareButtonDisabled } from '../../functions';
  13. interface IProps extends AbstractButtonProps {
  14. /**
  15. * Whether or not screensharing is initialized.
  16. */
  17. _desktopSharingEnabled: boolean;
  18. /**
  19. * Whether or not the local participant is screensharing.
  20. */
  21. _screensharing: boolean;
  22. }
  23. /**
  24. * Implementation of a button for sharing desktop / windows.
  25. */
  26. class ShareDesktopButton extends AbstractButton<IProps> {
  27. accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
  28. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.stopScreenSharing';
  29. label = 'toolbar.startScreenSharing';
  30. icon = IconScreenshare;
  31. toggledIcon = IconStopScreenshare;
  32. toggledLabel = 'toolbar.stopScreenSharing';
  33. /**
  34. * Retrieves tooltip dynamically.
  35. *
  36. * @returns {string}
  37. */
  38. _getTooltip() {
  39. const { _desktopSharingEnabled, _screensharing } = this.props;
  40. if (_desktopSharingEnabled) {
  41. if (_screensharing) {
  42. return 'toolbar.stopScreenSharing';
  43. }
  44. return 'toolbar.startScreenSharing';
  45. }
  46. return 'dialog.shareYourScreenDisabled';
  47. }
  48. /**
  49. * Indicates whether this button is in toggled state or not.
  50. *
  51. * @override
  52. * @protected
  53. * @returns {boolean}
  54. */
  55. _isToggled() {
  56. return this.props._screensharing;
  57. }
  58. /**
  59. * Indicates whether this button is in disabled state or not.
  60. *
  61. * @override
  62. * @protected
  63. * @returns {boolean}
  64. */
  65. _isDisabled() {
  66. return !this.props._desktopSharingEnabled;
  67. }
  68. /**
  69. * Handles clicking the button, and toggles the chat.
  70. *
  71. * @private
  72. * @returns {void}
  73. */
  74. _handleClick() {
  75. const { dispatch, _screensharing } = this.props;
  76. sendAnalytics(createToolbarEvent(
  77. 'toggle.screen.sharing',
  78. { enable: !_screensharing }));
  79. dispatch(closeOverflowMenuIfOpen());
  80. dispatch(startScreenShareFlow(!_screensharing));
  81. }
  82. }
  83. /**
  84. * Function that maps parts of Redux state tree into component props.
  85. *
  86. * @param {Object} state - Redux state.
  87. * @returns {Object}
  88. */
  89. const mapStateToProps = (state: IReduxState) => {
  90. // Disable the screenshare button if the video sender limit is reached and there is no video or media share in
  91. // progress.
  92. const desktopSharingEnabled
  93. = JitsiMeetJS.isDesktopSharingEnabled() && !isDesktopShareButtonDisabled(state);
  94. return {
  95. _desktopSharingEnabled: desktopSharingEnabled,
  96. _screensharing: isScreenVideoShared(state),
  97. visible: JitsiMeetJS.isDesktopSharingEnabled()
  98. };
  99. };
  100. export default translate(connect(mapStateToProps)(ShareDesktopButton));