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

AbstractLiveStreamButton.js 4.7KB

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