Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AbstractLiveStreamButton.ts 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { IReduxState } from '../../../app/types';
  2. import { IconSites } from '../../../base/icons/svg';
  3. import { MEET_FEATURES } from '../../../base/jwt/constants';
  4. import { isJwtFeatureEnabled } from '../../../base/jwt/functions';
  5. import { JitsiRecordingConstants } from '../../../base/lib-jitsi-meet';
  6. import { isLocalParticipantModerator } from '../../../base/participants/functions';
  7. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  8. import { isInBreakoutRoom } from '../../../breakout-rooms/functions';
  9. import { maybeShowPremiumFeatureDialog } from '../../../jaas/actions';
  10. import { getActiveSession } from '../../functions';
  11. import { getLiveStreaming } from './functions';
  12. /**
  13. * The type of the React {@code Component} props of
  14. * {@link AbstractLiveStreamButton}.
  15. */
  16. export interface IProps extends AbstractButtonProps {
  17. /**
  18. * True if the button needs to be disabled.
  19. */
  20. _disabled: boolean;
  21. /**
  22. * True if there is a running active live stream, false otherwise.
  23. */
  24. _isLiveStreamRunning: boolean;
  25. /**
  26. * The tooltip to display when hovering over the button.
  27. */
  28. _tooltip?: string;
  29. }
  30. /**
  31. * An abstract class of a button for starting and stopping live streaming.
  32. */
  33. export default class AbstractLiveStreamButton<P extends IProps> extends AbstractButton<P> {
  34. accessibilityLabel = 'dialog.accessibilityLabel.liveStreaming';
  35. icon = IconSites;
  36. label = 'dialog.startLiveStreaming';
  37. toggledLabel = 'dialog.stopLiveStreaming';
  38. /**
  39. * Returns the tooltip that should be displayed when the button is disabled.
  40. *
  41. * @private
  42. * @returns {string}
  43. */
  44. _getTooltip() {
  45. return this.props._tooltip ?? '';
  46. }
  47. /**
  48. * Helper function to be implemented by subclasses, which should be used
  49. * to handle the live stream button being clicked / pressed.
  50. *
  51. * @protected
  52. * @returns {void}
  53. */
  54. _onHandleClick() {
  55. // To be implemented by subclass.
  56. }
  57. /**
  58. * Handles clicking / pressing the button.
  59. *
  60. * @override
  61. * @protected
  62. * @returns {void}
  63. */
  64. async _handleClick() {
  65. const { dispatch } = this.props;
  66. const dialogShown = await dispatch(maybeShowPremiumFeatureDialog(MEET_FEATURES.RECORDING));
  67. if (!dialogShown) {
  68. this._onHandleClick();
  69. }
  70. }
  71. /**
  72. * Returns a boolean value indicating if this button is disabled or not.
  73. *
  74. * @protected
  75. * @returns {boolean}
  76. */
  77. _isDisabled() {
  78. return this.props._disabled;
  79. }
  80. /**
  81. * Indicates whether this button is in toggled state or not.
  82. *
  83. * @override
  84. * @protected
  85. * @returns {boolean}
  86. */
  87. _isToggled() {
  88. return this.props._isLiveStreamRunning;
  89. }
  90. }
  91. /**
  92. * Maps (parts of) the redux state to the associated props for the
  93. * {@code AbstractLiveStreamButton} component.
  94. *
  95. * @param {Object} state - The Redux state.
  96. * @param {IProps} ownProps - The own props of the Component.
  97. * @private
  98. * @returns {{
  99. * _disabled: boolean,
  100. * _isLiveStreamRunning: boolean,
  101. * visible: boolean
  102. * }}
  103. */
  104. export function _mapStateToProps(state: IReduxState, ownProps: IProps) {
  105. let { visible } = ownProps;
  106. // A button can be disabled/enabled only if enableFeaturesBasedOnToken
  107. // is on or if the recording is running.
  108. let _disabled = false;
  109. let _tooltip = '';
  110. if (typeof visible === 'undefined') {
  111. // If the containing component provides the visible prop, that is one
  112. // above all, but if not, the button should be autonomous and decide on
  113. // its own to be visible or not.
  114. const isModerator = isLocalParticipantModerator(state);
  115. const liveStreaming = getLiveStreaming(state);
  116. if (isModerator) {
  117. visible = liveStreaming.enabled ? isJwtFeatureEnabled(state, 'livestreaming', true) : false;
  118. } else {
  119. visible = false;
  120. }
  121. }
  122. // disable the button if the recording is running.
  123. if (visible && getActiveSession(state, JitsiRecordingConstants.mode.FILE)) {
  124. _disabled = true;
  125. _tooltip = 'dialog.liveStreamingDisabledBecauseOfActiveRecordingTooltip';
  126. }
  127. // disable the button if we are in a breakout room.
  128. if (isInBreakoutRoom(state)) {
  129. _disabled = true;
  130. visible = false;
  131. }
  132. return {
  133. _disabled,
  134. _isLiveStreamRunning: Boolean(getActiveSession(state, JitsiRecordingConstants.mode.STREAM)),
  135. _tooltip,
  136. visible
  137. };
  138. }