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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // @flow
  2. import { translate } from '../../../base/i18n';
  3. import { IconShareDesktop } from '../../../base/icons';
  4. import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
  5. import { connect } from '../../../base/redux';
  6. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  7. import { isScreenVideoShared } from '../../../screen-share';
  8. import { isDesktopShareButtonDisabled } from '../../functions';
  9. type Props = AbstractButtonProps & {
  10. /**
  11. * Whether or not screensharing is initialized.
  12. */
  13. _desktopSharingEnabled: boolean,
  14. /**
  15. * Whether or not the local participant is screensharing.
  16. */
  17. _screensharing: boolean,
  18. /**
  19. * The redux {@code dispatch} function.
  20. */
  21. dispatch: Function,
  22. };
  23. /**
  24. * Implementation of a button for sharing desktop / windows.
  25. */
  26. class ShareDesktopButton extends AbstractButton<Props, *> {
  27. accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
  28. label = 'toolbar.startScreenSharing';
  29. icon = IconShareDesktop;
  30. toggledLabel = 'toolbar.stopScreenSharing';
  31. tooltip = 'toolbar.accessibilityLabel.shareYourScreen';
  32. /**
  33. * Retrieves tooltip dynamically.
  34. */
  35. get tooltip() {
  36. const { _desktopSharingEnabled, _screensharing } = this.props;
  37. if (_desktopSharingEnabled) {
  38. if (_screensharing) {
  39. return 'toolbar.stopScreenSharing';
  40. }
  41. return 'toolbar.startScreenSharing';
  42. }
  43. return 'dialog.shareYourScreenDisabled';
  44. }
  45. /**
  46. * Required by linter due to AbstractButton overwritten prop being writable.
  47. *
  48. * @param {string} _value - The icon value.
  49. */
  50. set tooltip(_value) {
  51. // Unused.
  52. }
  53. /**
  54. * Indicates whether this button is in toggled state or not.
  55. *
  56. * @override
  57. * @protected
  58. * @returns {boolean}
  59. */
  60. _isToggled() {
  61. return this.props._screensharing;
  62. }
  63. /**
  64. * Indicates whether this button is in disabled state or not.
  65. *
  66. * @override
  67. * @protected
  68. * @returns {boolean}
  69. */
  70. _isDisabled() {
  71. return !this.props._desktopSharingEnabled;
  72. }
  73. }
  74. /**
  75. * Function that maps parts of Redux state tree into component props.
  76. *
  77. * @param {Object} state - Redux state.
  78. * @returns {Object}
  79. */
  80. const mapStateToProps = state => {
  81. // Disable the screenshare button if the video sender limit is reached and there is no video or media share in
  82. // progress.
  83. const desktopSharingEnabled
  84. = JitsiMeetJS.isDesktopSharingEnabled() && !isDesktopShareButtonDisabled(state);
  85. return {
  86. _desktopSharingEnabled: desktopSharingEnabled,
  87. _screensharing: isScreenVideoShared(state)
  88. };
  89. };
  90. export default translate(connect(mapStateToProps)(ShareDesktopButton));