2020-05-20 08:25:31 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { isLocalParticipantModerator } from '../../../base/participants';
|
|
|
|
import { Switch } from '../../../base/react';
|
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import { toggleLobbyMode } from '../../actions';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if lobby is currently enabled in the conference.
|
|
|
|
*/
|
|
|
|
_lobbyEnabled: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the section should be visible.
|
|
|
|
*/
|
|
|
|
_visible: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Redux Dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to be used to translate i18n labels.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the lobby switch is toggled on.
|
|
|
|
*/
|
|
|
|
lobbyEnabled: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a security feature section to control lobby mode.
|
|
|
|
*/
|
|
|
|
class LobbySection extends PureComponent<Props, State> {
|
|
|
|
/**
|
|
|
|
* Instantiates a new component.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
lobbyEnabled: props._lobbyEnabled
|
|
|
|
};
|
|
|
|
|
|
|
|
this._onToggleLobby = this._onToggleLobby.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-07-10 16:50:45 +00:00
|
|
|
* Implements React's {@link Component#getDerivedStateFromProps()}.
|
2020-05-20 08:25:31 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2020-07-10 16:50:45 +00:00
|
|
|
static getDerivedStateFromProps(props: Props, state: Object) {
|
|
|
|
if (props._lobbyEnabled !== state.lobbyEnabled) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
lobbyEnabled: props._lobbyEnabled
|
|
|
|
};
|
2020-05-20 08:25:31 +00:00
|
|
|
}
|
2020-07-10 16:50:45 +00:00
|
|
|
|
|
|
|
return null;
|
2020-05-20 08:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements {@code PureComponent#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { _visible, t } = this.props;
|
|
|
|
|
|
|
|
if (!_visible) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-06-24 12:12:23 +00:00
|
|
|
<>
|
|
|
|
<div id = 'lobby-section'>
|
2020-06-25 13:44:17 +00:00
|
|
|
<p className = 'description'>
|
|
|
|
{ t('lobby.enableDialogText') }
|
|
|
|
</p>
|
2020-06-24 12:12:23 +00:00
|
|
|
<div className = 'control-row'>
|
|
|
|
<label>
|
|
|
|
{ t('lobby.toggleLabel') }
|
|
|
|
</label>
|
|
|
|
<Switch
|
|
|
|
onValueChange = { this._onToggleLobby }
|
|
|
|
value = { this.state.lobbyEnabled } />
|
|
|
|
</div>
|
2020-05-20 08:25:31 +00:00
|
|
|
</div>
|
2020-06-24 12:12:23 +00:00
|
|
|
<div className = 'separator-line' />
|
|
|
|
</>
|
2020-05-20 08:25:31 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onToggleLobby: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to be invoked when the user toggles the lobby feature on or off.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onToggleLobby() {
|
|
|
|
const newValue = !this.state.lobbyEnabled;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
lobbyEnabled: newValue
|
|
|
|
});
|
|
|
|
|
|
|
|
this.props.dispatch(toggleLobbyMode(newValue));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the Redux state to the props of this component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @returns {Props}
|
|
|
|
*/
|
|
|
|
function mapStateToProps(state: Object): $Shape<Props> {
|
|
|
|
const { conference } = state['features/base/conference'];
|
|
|
|
|
|
|
|
return {
|
|
|
|
_lobbyEnabled: state['features/lobby'].lobbyEnabled,
|
|
|
|
_visible: conference && conference.isLobbySupported() && isLocalParticipantModerator(state)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(mapStateToProps)(LobbySection));
|