2018-07-05 11:17:45 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-04-29 22:35:27 +00:00
|
|
|
import { IconLiveStreaming } from '../../../base/icons';
|
2022-08-16 12:53:53 +00:00
|
|
|
import { isJwtFeatureEnabled } from '../../../base/jwt/functions';
|
2018-07-05 11:17:45 +00:00
|
|
|
import { JitsiRecordingConstants } from '../../../base/lib-jitsi-meet';
|
2022-08-16 12:53:53 +00:00
|
|
|
import { isLocalParticipantModerator } from '../../../base/participants';
|
2020-07-24 12:14:33 +00:00
|
|
|
import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
|
2021-11-30 14:08:32 +00:00
|
|
|
import { isInBreakoutRoom } from '../../../breakout-rooms/functions';
|
2021-06-25 13:28:54 +00:00
|
|
|
import { maybeShowPremiumFeatureDialog } from '../../../jaas/actions';
|
|
|
|
import { FEATURES } from '../../../jaas/constants';
|
2018-07-05 11:17:45 +00:00
|
|
|
import { getActiveSession } from '../../functions';
|
|
|
|
|
2022-08-02 08:27:18 +00:00
|
|
|
import { getLiveStreaming } from './functions';
|
|
|
|
|
2018-07-05 11:17:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of
|
|
|
|
* {@link AbstractLiveStreamButton}.
|
|
|
|
*/
|
|
|
|
export type Props = AbstractButtonProps & {
|
|
|
|
|
|
|
|
/**
|
2022-02-08 11:25:32 +00:00
|
|
|
* True if the button needs to be disabled.
|
2018-07-05 11:17:45 +00:00
|
|
|
*/
|
2022-02-08 11:25:32 +00:00
|
|
|
_disabled: Boolean,
|
2018-07-05 11:17:45 +00:00
|
|
|
|
2020-04-29 17:06:08 +00:00
|
|
|
/**
|
2022-02-08 11:25:32 +00:00
|
|
|
* True if there is a running active live stream, false otherwise.
|
2020-04-29 17:06:08 +00:00
|
|
|
*/
|
2022-02-08 11:25:32 +00:00
|
|
|
_isLiveStreamRunning: boolean,
|
2020-04-29 17:06:08 +00:00
|
|
|
|
2020-04-29 22:35:27 +00:00
|
|
|
/**
|
|
|
|
* The tooltip to display when hovering over the button.
|
|
|
|
*/
|
|
|
|
_tooltip: ?String,
|
|
|
|
|
2018-07-05 11:17:45 +00:00
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The i18n translate function.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An abstract class of a button for starting and stopping live streaming.
|
|
|
|
*/
|
2020-04-29 22:35:27 +00:00
|
|
|
export default class AbstractLiveStreamButton<P: Props> extends AbstractButton<P, *> {
|
2018-07-05 11:17:45 +00:00
|
|
|
accessibilityLabel = 'dialog.accessibilityLabel.liveStreaming';
|
2020-04-29 22:35:27 +00:00
|
|
|
icon = IconLiveStreaming;
|
2018-07-05 11:17:45 +00:00
|
|
|
label = 'dialog.startLiveStreaming';
|
|
|
|
toggledLabel = 'dialog.stopLiveStreaming';
|
|
|
|
|
2020-04-29 22:35:27 +00:00
|
|
|
/**
|
|
|
|
* Returns the tooltip that should be displayed when the button is disabled.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_getTooltip() {
|
|
|
|
return this.props._tooltip || '';
|
|
|
|
}
|
|
|
|
|
2022-02-08 11:25:32 +00:00
|
|
|
/**
|
|
|
|
* Helper function to be implemented by subclasses, which should be used
|
|
|
|
* to handle the live stream button being clicked / pressed.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onHandleClick() {
|
|
|
|
// To be implemented by subclass.
|
|
|
|
}
|
|
|
|
|
2018-07-05 11:17:45 +00:00
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button.
|
|
|
|
*
|
|
|
|
* @override
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-06-25 13:28:54 +00:00
|
|
|
async _handleClick() {
|
2022-02-08 11:25:32 +00:00
|
|
|
const { dispatch } = this.props;
|
2018-07-05 11:17:45 +00:00
|
|
|
|
2021-06-25 13:28:54 +00:00
|
|
|
const dialogShown = await dispatch(maybeShowPremiumFeatureDialog(FEATURES.RECORDING));
|
|
|
|
|
|
|
|
if (!dialogShown) {
|
2022-02-08 11:25:32 +00:00
|
|
|
this._onHandleClick();
|
2021-06-25 13:28:54 +00:00
|
|
|
}
|
2018-07-05 11:17:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 22:35:27 +00:00
|
|
|
/**
|
|
|
|
* Returns a boolean value indicating if this button is disabled or not.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isDisabled() {
|
|
|
|
return this.props._disabled;
|
|
|
|
}
|
|
|
|
|
2018-07-05 11:17:45 +00:00
|
|
|
/**
|
|
|
|
* Indicates whether this button is in toggled state or not.
|
|
|
|
*
|
|
|
|
* @override
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isToggled() {
|
|
|
|
return this.props._isLiveStreamRunning;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated props for the
|
|
|
|
* {@code AbstractLiveStreamButton} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @param {Props} ownProps - The own props of the Component.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
2020-04-29 17:06:08 +00:00
|
|
|
* _disabled: boolean,
|
2018-07-05 11:17:45 +00:00
|
|
|
* _isLiveStreamRunning: boolean,
|
|
|
|
* visible: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function _mapStateToProps(state: Object, ownProps: Props) {
|
|
|
|
let { visible } = ownProps;
|
|
|
|
|
2020-04-29 17:06:08 +00:00
|
|
|
// A button can be disabled/enabled only if enableFeaturesBasedOnToken
|
|
|
|
// is on or if the recording is running.
|
2022-08-16 12:53:53 +00:00
|
|
|
let _disabled = false;
|
2020-04-29 22:35:27 +00:00
|
|
|
let _tooltip = '';
|
2018-09-11 22:33:45 +00:00
|
|
|
|
2018-07-05 11:17:45 +00:00
|
|
|
if (typeof visible === 'undefined') {
|
|
|
|
// If the containing component provides the visible prop, that is one
|
2022-08-16 12:53:53 +00:00
|
|
|
// above all, but if not, the button should be autonomous and decide on
|
2018-07-05 11:17:45 +00:00
|
|
|
// its own to be visible or not.
|
2020-09-25 11:37:05 +00:00
|
|
|
const isModerator = isLocalParticipantModerator(state);
|
2022-08-02 08:27:18 +00:00
|
|
|
const liveStreaming = getLiveStreaming(state);
|
2018-07-05 11:17:45 +00:00
|
|
|
|
2022-08-02 08:27:18 +00:00
|
|
|
visible = isModerator && liveStreaming.enabled;
|
2022-08-16 12:53:53 +00:00
|
|
|
visible = isJwtFeatureEnabled(state, 'livestreaming', visible);
|
2018-07-05 11:17:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 17:06:08 +00:00
|
|
|
// disable the button if the recording is running.
|
2022-08-16 12:53:53 +00:00
|
|
|
if (visible && getActiveSession(state, JitsiRecordingConstants.mode.FILE)) {
|
2020-04-29 17:06:08 +00:00
|
|
|
_disabled = true;
|
2020-04-29 22:35:27 +00:00
|
|
|
_tooltip = 'dialog.liveStreamingDisabledBecauseOfActiveRecordingTooltip';
|
2020-04-29 17:06:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 14:08:32 +00:00
|
|
|
// disable the button if we are in a breakout room.
|
|
|
|
if (isInBreakoutRoom(state)) {
|
|
|
|
_disabled = true;
|
|
|
|
visible = false;
|
|
|
|
}
|
|
|
|
|
2018-07-05 11:17:45 +00:00
|
|
|
return {
|
2020-04-29 17:06:08 +00:00
|
|
|
_disabled,
|
2022-08-16 12:53:53 +00:00
|
|
|
_isLiveStreamRunning: Boolean(getActiveSession(state, JitsiRecordingConstants.mode.STREAM)),
|
2020-04-29 22:35:27 +00:00
|
|
|
_tooltip,
|
2018-07-05 11:17:45 +00:00
|
|
|
visible
|
|
|
|
};
|
|
|
|
}
|