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

AbstractLiveStreamButton.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 { getActiveSession } from '../../functions';
  11. import {
  12. StartLiveStreamDialog,
  13. StopLiveStreamDialog
  14. } from './_';
  15. /**
  16. * The type of the React {@code Component} props of
  17. * {@link AbstractLiveStreamButton}.
  18. */
  19. export type Props = AbstractButtonProps & {
  20. /**
  21. * True if there is a running active live stream, false otherwise.
  22. */
  23. _isLiveStreamRunning: boolean,
  24. /**
  25. * True if the button needs to be disabled.
  26. */
  27. _disabled: Boolean,
  28. /**
  29. * The tooltip to display when hovering over the button.
  30. */
  31. _tooltip: ?String,
  32. /**
  33. * The redux {@code dispatch} function.
  34. */
  35. dispatch: Function,
  36. /**
  37. * The i18n translate function.
  38. */
  39. t: Function
  40. };
  41. /**
  42. * An abstract class of a button for starting and stopping live streaming.
  43. */
  44. export default class AbstractLiveStreamButton<P: Props> extends AbstractButton<P, *> {
  45. accessibilityLabel = 'dialog.accessibilityLabel.liveStreaming';
  46. icon = IconLiveStreaming;
  47. label = 'dialog.startLiveStreaming';
  48. toggledLabel = 'dialog.stopLiveStreaming';
  49. /**
  50. * Returns the tooltip that should be displayed when the button is disabled.
  51. *
  52. * @private
  53. * @returns {string}
  54. */
  55. _getTooltip() {
  56. return this.props._tooltip || '';
  57. }
  58. /**
  59. * Handles clicking / pressing the button.
  60. *
  61. * @override
  62. * @protected
  63. * @returns {void}
  64. */
  65. _handleClick() {
  66. const { _isLiveStreamRunning, dispatch } = this.props;
  67. dispatch(openDialog(
  68. _isLiveStreamRunning ? StopLiveStreamDialog : StartLiveStreamDialog
  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 {Props} 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: Object, ownProps: Props) {
  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;
  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 autonomus and decide on
  113. // its own to be visible or not.
  114. const isModerator = isLocalParticipantModerator(state);
  115. const {
  116. enableFeaturesBasedOnToken,
  117. liveStreamingEnabled
  118. } = state['features/base/config'];
  119. const { features = {} } = getLocalParticipant(state);
  120. visible = isModerator && liveStreamingEnabled;
  121. if (enableFeaturesBasedOnToken) {
  122. visible = visible && String(features.livestreaming) === 'true';
  123. _disabled = String(features.livestreaming) === 'disabled';
  124. if (!visible && !_disabled) {
  125. _disabled = true;
  126. visible = true;
  127. _tooltip = 'dialog.liveStreamingDisabledTooltip';
  128. }
  129. }
  130. }
  131. // disable the button if the recording is running.
  132. if (getActiveSession(state, JitsiRecordingConstants.mode.FILE)) {
  133. _disabled = true;
  134. _tooltip = 'dialog.liveStreamingDisabledBecauseOfActiveRecordingTooltip';
  135. }
  136. return {
  137. _disabled,
  138. _isLiveStreamRunning: Boolean(
  139. getActiveSession(state, JitsiRecordingConstants.mode.STREAM)),
  140. _tooltip,
  141. visible
  142. };
  143. }