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.9KB

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