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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. type Props = AbstractButtonProps & {
  9. /**
  10. * Whether or not screensharing is initialized.
  11. */
  12. _desktopSharingEnabled: boolean,
  13. /**
  14. * The tooltip key to use when screensharing is disabled. Or undefined
  15. * if non to be shown and the button to be hidden.
  16. */
  17. _desktopSharingDisabledTooltipKey: string,
  18. /**
  19. * Whether or not the local participant is screensharing.
  20. */
  21. _screensharing: boolean,
  22. /**
  23. * The redux {@code dispatch} function.
  24. */
  25. dispatch: Function,
  26. };
  27. /**
  28. * Implementation of a button for sharing desktop / windows.
  29. */
  30. class ShareDesktopButton extends AbstractButton<Props, *> {
  31. accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
  32. label = 'toolbar.startScreenSharing';
  33. icon = IconShareDesktop;
  34. toggledLabel = 'toolbar.stopScreenSharing'
  35. tooltip = 'toolbar.accessibilityLabel.shareYourScreen';
  36. /**
  37. * Retrieves tooltip dynamically.
  38. */
  39. get tooltip() {
  40. const { _desktopSharingDisabledTooltipKey, _desktopSharingEnabled, _screensharing } = this.props;
  41. if (_desktopSharingEnabled) {
  42. if (_screensharing) {
  43. return 'toolbar.stopScreenSharing';
  44. }
  45. return 'toolbar.startScreenSharing';
  46. }
  47. return _desktopSharingDisabledTooltipKey;
  48. }
  49. /**
  50. * Required by linter due to AbstractButton overwritten prop being writable.
  51. *
  52. * @param {string} value - The icon value.
  53. */
  54. set tooltip(value) {
  55. return value;
  56. }
  57. /**
  58. * Handles clicking / pressing the button, and opens the appropriate dialog.
  59. *
  60. * @protected
  61. * @returns {void}
  62. */
  63. _handleClick() {
  64. const { handleClick } = this.props;
  65. if (handleClick) {
  66. handleClick();
  67. return;
  68. }
  69. }
  70. /**
  71. * Indicates whether this button is in toggled state or not.
  72. *
  73. * @override
  74. * @protected
  75. * @returns {boolean}
  76. */
  77. _isToggled() {
  78. return this.props._screensharing;
  79. }
  80. /**
  81. * Indicates whether this button is in disabled state or not.
  82. *
  83. * @override
  84. * @protected
  85. * @returns {boolean}
  86. */
  87. _isDisabled() {
  88. return !this.props._desktopSharingEnabled;
  89. }
  90. }
  91. /**
  92. * Function that maps parts of Redux state tree into component props.
  93. *
  94. * @param {Object} state - Redux state.
  95. * @returns {Object}
  96. */
  97. const mapStateToProps = state => {
  98. let desktopSharingEnabled = JitsiMeetJS.isDesktopSharingEnabled();
  99. const { enableFeaturesBasedOnToken } = state['features/base/config'];
  100. let desktopSharingDisabledTooltipKey;
  101. if (enableFeaturesBasedOnToken) {
  102. // we enable desktop sharing if any participant already have this
  103. // feature enabled
  104. desktopSharingEnabled = state['features/base/participants'].haveParticipantWithScreenSharingFeature;
  105. desktopSharingDisabledTooltipKey = 'dialog.shareYourScreenDisabled';
  106. }
  107. return {
  108. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  109. _desktopSharingEnabled: desktopSharingEnabled,
  110. _screensharing: isScreenVideoShared(state)
  111. };
  112. };
  113. export default translate(connect(mapStateToProps)(ShareDesktopButton));