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

AbstractLiveStreamButton.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // @flow
  2. import { openDialog } from '../../../base/dialog';
  3. import { JitsiRecordingConstants } from '../../../base/lib-jitsi-meet';
  4. import {
  5. isLocalParticipantModerator,
  6. getLocalParticipant
  7. } from '../../../base/participants';
  8. import {
  9. AbstractButton,
  10. type AbstractButtonProps
  11. } from '../../../base/toolbox';
  12. import { getActiveSession } from '../../functions';
  13. import StartLiveStreamDialog from './StartLiveStreamDialog';
  14. import StopLiveStreamDialog from './StopLiveStreamDialog';
  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. * The redux {@code dispatch} function.
  26. */
  27. dispatch: Function,
  28. /**
  29. * The i18n translate function.
  30. */
  31. t: Function
  32. };
  33. /**
  34. * An abstract class of a button for starting and stopping live streaming.
  35. */
  36. export default class AbstractLiveStreamButton<P: Props>
  37. extends AbstractButton<P, *> {
  38. accessibilityLabel = 'dialog.accessibilityLabel.liveStreaming';
  39. label = 'dialog.startLiveStreaming';
  40. toggledLabel = 'dialog.stopLiveStreaming';
  41. /**
  42. * Handles clicking / pressing the button.
  43. *
  44. * @override
  45. * @protected
  46. * @returns {void}
  47. */
  48. _handleClick() {
  49. const { _isLiveStreamRunning, dispatch } = this.props;
  50. dispatch(openDialog(
  51. _isLiveStreamRunning ? StopLiveStreamDialog : StartLiveStreamDialog
  52. ));
  53. }
  54. /**
  55. * Indicates whether this button is in toggled state or not.
  56. *
  57. * @override
  58. * @protected
  59. * @returns {boolean}
  60. */
  61. _isToggled() {
  62. return this.props._isLiveStreamRunning;
  63. }
  64. }
  65. /**
  66. * Maps (parts of) the redux state to the associated props for the
  67. * {@code AbstractLiveStreamButton} component.
  68. *
  69. * @param {Object} state - The Redux state.
  70. * @param {Props} ownProps - The own props of the Component.
  71. * @private
  72. * @returns {{
  73. * _isLiveStreamRunning: boolean,
  74. * visible: boolean
  75. * }}
  76. */
  77. export function _mapStateToProps(state: Object, ownProps: Props) {
  78. let { visible } = ownProps;
  79. if (typeof visible === 'undefined') {
  80. // If the containing component provides the visible prop, that is one
  81. // above all, but if not, the button should be autonomus and decide on
  82. // its own to be visible or not.
  83. const isModerator = isLocalParticipantModerator(state);
  84. const {
  85. enableFeaturesBasedOnToken,
  86. liveStreamingEnabled
  87. } = state['features/base/config'];
  88. const { features = {} } = getLocalParticipant(state);
  89. visible = isModerator
  90. && liveStreamingEnabled
  91. && (!enableFeaturesBasedOnToken
  92. || String(features.livestreaming) === 'true');
  93. }
  94. return {
  95. _isLiveStreamRunning: Boolean(
  96. getActiveSession(state, JitsiRecordingConstants.mode.STREAM)),
  97. visible
  98. };
  99. }