You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractLiveStreamButton.js 3.1KB

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