您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ShareDesktopButton.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 { getLocalVideoTrack } from '../../../base/tracks';
  8. import { isScreenAudioShared } from '../../../screen-share';
  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. * External handler for click action.
  29. */
  30. handleClick: Function
  31. };
  32. /**
  33. * Implementation of a button for sharing desktop / windows.
  34. */
  35. class ShareDesktopButton extends AbstractButton<Props, *> {
  36. accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
  37. label = 'toolbar.startScreenSharing';
  38. icon = IconShareDesktop;
  39. toggledLabel = 'toolbar.stopScreenSharing'
  40. tooltip = 'toolbar.accessibilityLabel.shareYourScreen';
  41. /**
  42. * Retrieves tooltip dynamically.
  43. */
  44. get tooltip() {
  45. const { _desktopSharingDisabledTooltipKey, _desktopSharingEnabled, _screensharing } = this.props;
  46. if (_desktopSharingEnabled) {
  47. if (_screensharing) {
  48. return 'toolbar.stopScreenSharing';
  49. }
  50. return 'toolbar.startScreenSharing';
  51. }
  52. return _desktopSharingDisabledTooltipKey;
  53. }
  54. /**
  55. * Required by linter due to AbstractButton overwritten prop being writable.
  56. *
  57. * @param {string} value - The icon value.
  58. */
  59. set tooltip(value) {
  60. return value;
  61. }
  62. /**
  63. * Handles clicking / pressing the button, and opens the appropriate dialog.
  64. *
  65. * @protected
  66. * @returns {void}
  67. */
  68. _handleClick() {
  69. this.props.handleClick();
  70. }
  71. /**
  72. * Indicates whether this button is in toggled state or not.
  73. *
  74. * @override
  75. * @protected
  76. * @returns {boolean}
  77. */
  78. _isToggled() {
  79. return this.props._screensharing;
  80. }
  81. /**
  82. * Indicates whether this button is in disabled state or not.
  83. *
  84. * @override
  85. * @protected
  86. * @returns {boolean}
  87. */
  88. _isDisabled() {
  89. return !this.props._desktopSharingEnabled;
  90. }
  91. }
  92. /**
  93. * Function that maps parts of Redux state tree into component props.
  94. *
  95. * @param {Object} state - Redux state.
  96. * @returns {Object}
  97. */
  98. const mapStateToProps = state => {
  99. const localVideo = getLocalVideoTrack(state['features/base/tracks']);
  100. let desktopSharingEnabled = JitsiMeetJS.isDesktopSharingEnabled();
  101. const { enableFeaturesBasedOnToken } = state['features/base/config'];
  102. let desktopSharingDisabledTooltipKey;
  103. if (enableFeaturesBasedOnToken) {
  104. // we enable desktop sharing if any participant already have this
  105. // feature enabled
  106. desktopSharingEnabled = state['features/base/participants'].haveParticipantWithScreenSharingFeature;
  107. desktopSharingDisabledTooltipKey = 'dialog.shareYourScreenDisabled';
  108. }
  109. return {
  110. _desktopSharingDisabledTooltipKey: desktopSharingDisabledTooltipKey,
  111. _desktopSharingEnabled: desktopSharingEnabled,
  112. _screensharing: (localVideo && localVideo.videoType === 'desktop') || isScreenAudioShared(state)
  113. };
  114. };
  115. export default translate(connect(mapStateToProps)(ShareDesktopButton));