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

AbstractLiveStreamButton.js 4.5KB

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