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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // @flow
  2. import { IconLiveStreaming } from '../../../base/icons';
  3. import { JitsiRecordingConstants } from '../../../base/lib-jitsi-meet';
  4. import {
  5. getLocalParticipant,
  6. isLocalParticipantModerator
  7. } from '../../../base/participants';
  8. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  9. import { isInBreakoutRoom } from '../../../breakout-rooms/functions';
  10. import { maybeShowPremiumFeatureDialog } from '../../../jaas/actions';
  11. import { FEATURES } from '../../../jaas/constants';
  12. import { getActiveSession } from '../../functions';
  13. /**
  14. * The type of the React {@code Component} props of
  15. * {@link AbstractLiveStreamButton}.
  16. */
  17. export type Props = AbstractButtonProps & {
  18. /**
  19. * True if the button needs to be disabled.
  20. */
  21. _disabled: Boolean,
  22. /**
  23. * True if there is a running active live stream, false otherwise.
  24. */
  25. _isLiveStreamRunning: boolean,
  26. /**
  27. * The tooltip to display when hovering over the button.
  28. */
  29. _tooltip: ?String,
  30. /**
  31. * The redux {@code dispatch} function.
  32. */
  33. dispatch: Function,
  34. /**
  35. * The i18n translate function.
  36. */
  37. t: Function
  38. };
  39. /**
  40. * An abstract class of a button for starting and stopping live streaming.
  41. */
  42. export default class AbstractLiveStreamButton<P: Props> extends AbstractButton<P, *> {
  43. accessibilityLabel = 'dialog.accessibilityLabel.liveStreaming';
  44. icon = IconLiveStreaming;
  45. label = 'dialog.startLiveStreaming';
  46. toggledLabel = 'dialog.stopLiveStreaming';
  47. /**
  48. * Returns the tooltip that should be displayed when the button is disabled.
  49. *
  50. * @private
  51. * @returns {string}
  52. */
  53. _getTooltip() {
  54. return this.props._tooltip || '';
  55. }
  56. /**
  57. * Helper function to be implemented by subclasses, which should be used
  58. * to handle the live stream button being clicked / pressed.
  59. *
  60. * @protected
  61. * @returns {void}
  62. */
  63. _onHandleClick() {
  64. // To be implemented by subclass.
  65. }
  66. /**
  67. * Handles clicking / pressing the button.
  68. *
  69. * @override
  70. * @protected
  71. * @returns {void}
  72. */
  73. async _handleClick() {
  74. const { dispatch } = this.props;
  75. const dialogShown = await dispatch(maybeShowPremiumFeatureDialog(FEATURES.RECORDING));
  76. if (!dialogShown) {
  77. this._onHandleClick();
  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. // disable the button if we are in a breakout room.
  146. if (isInBreakoutRoom(state)) {
  147. _disabled = true;
  148. visible = false;
  149. }
  150. return {
  151. _disabled,
  152. _isLiveStreamRunning: Boolean(
  153. getActiveSession(state, JitsiRecordingConstants.mode.STREAM)),
  154. _tooltip,
  155. visible
  156. };
  157. }