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

ShareDesktopButton.js 3.6KB

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