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.

ShareDesktopButton.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 } 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.web';
  13. interface IProps extends AbstractButtonProps {
  14. /**
  15. * Whether or not screen-sharing is initialized.
  16. */
  17. _desktopSharingEnabled: boolean;
  18. /**
  19. * Whether or not the local participant is screen-sharing.
  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. toggledLabel = 'toolbar.stopScreenSharing';
  32. /**
  33. * Retrieves tooltip dynamically.
  34. *
  35. * @returns {string}
  36. */
  37. _getTooltip() {
  38. const { _desktopSharingEnabled, _screensharing } = this.props;
  39. if (_desktopSharingEnabled) {
  40. if (_screensharing) {
  41. return 'toolbar.stopScreenSharing';
  42. }
  43. return 'toolbar.startScreenSharing';
  44. }
  45. return 'dialog.shareYourScreenDisabled';
  46. }
  47. /**
  48. * Indicates whether this button is in toggled state or not.
  49. *
  50. * @override
  51. * @protected
  52. * @returns {boolean}
  53. */
  54. _isToggled() {
  55. return this.props._screensharing;
  56. }
  57. /**
  58. * Indicates whether this button is in disabled state or not.
  59. *
  60. * @override
  61. * @protected
  62. * @returns {boolean}
  63. */
  64. _isDisabled() {
  65. return !this.props._desktopSharingEnabled;
  66. }
  67. /**
  68. * Handles clicking the button, and toggles the chat.
  69. *
  70. * @private
  71. * @returns {void}
  72. */
  73. _handleClick() {
  74. const { dispatch, _screensharing } = this.props;
  75. sendAnalytics(createToolbarEvent(
  76. 'toggle.screen.sharing',
  77. { enable: !_screensharing }));
  78. dispatch(closeOverflowMenuIfOpen());
  79. dispatch(startScreenShareFlow(!_screensharing));
  80. }
  81. }
  82. /**
  83. * Function that maps parts of Redux state tree into component props.
  84. *
  85. * @param {Object} state - Redux state.
  86. * @returns {Object}
  87. */
  88. const mapStateToProps = (state: IReduxState) => {
  89. // Disable the screen-share button if the video sender limit is reached and there is no video or media share in
  90. // progress.
  91. const desktopSharingEnabled
  92. = JitsiMeetJS.isDesktopSharingEnabled() && !isDesktopShareButtonDisabled(state);
  93. return {
  94. _desktopSharingEnabled: desktopSharingEnabled,
  95. _screensharing: isScreenVideoShared(state),
  96. visible: JitsiMeetJS.isDesktopSharingEnabled()
  97. };
  98. };
  99. export default translate(connect(mapStateToProps)(ShareDesktopButton));