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 2.8KB

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