jiti-meet/react/features/lobby/components/web/LobbySection.tsx

144 lines
3.7 KiB
TypeScript
Raw Normal View History

/* eslint-disable lines-around-comment */
2020-05-20 08:25:31 +00:00
import React, { PureComponent } from 'react';
2022-08-08 09:36:06 +00:00
import { WithTranslation } from 'react-i18next';
2020-05-20 08:25:31 +00:00
2022-08-08 09:36:06 +00:00
import { translate } from '../../../base/i18n/functions';
import { isLocalParticipantModerator } from '../../../base/participants/functions';
import { connect } from '../../../base/redux/functions';
import Switch from '../../../base/ui/components/web/Switch';
// @ts-ignore
import { isInBreakoutRoom } from '../../../breakout-rooms/functions';
// @ts-ignore
2020-05-20 08:25:31 +00:00
import { toggleLobbyMode } from '../../actions';
2022-08-08 09:36:06 +00:00
interface Props extends WithTranslation {
2020-05-20 08:25:31 +00:00
/**
* True if lobby is currently enabled in the conference.
*/
_lobbyEnabled: boolean,
/**
* True if the section should be visible.
*/
_visible: boolean,
/**
* The Redux Dispatch function.
*/
2022-08-08 09:36:06 +00:00
dispatch: Function
}
2020-05-20 08:25:31 +00:00
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);
}
/**
* Implements React's {@link Component#getDerivedStateFromProps()}.
2020-05-20 08:25:31 +00:00
*
* @inheritdoc
*/
static getDerivedStateFromProps(props: Props, state: State) {
if (props._lobbyEnabled !== state.lobbyEnabled) {
return {
lobbyEnabled: props._lobbyEnabled
};
2020-05-20 08:25:31 +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 (
<>
<div id = 'lobby-section'>
<p
className = 'description'
role = 'banner'>
{ t('lobby.enableDialogText') }
</p>
<div className = 'control-row'>
2021-01-14 16:12:08 +00:00
<label htmlFor = 'lobby-section-switch'>
{ t('lobby.toggleLabel') }
</label>
<Switch
checked = { this.state.lobbyEnabled }
2021-01-14 16:12:08 +00:00
id = 'lobby-section-switch'
onChange = { this._onToggleLobby } />
</div>
2020-05-20 08:25:31 +00:00
</div>
<div className = 'separator-line' />
</>
2020-05-20 08:25:31 +00:00
);
}
/**
* 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: any): Partial<Props> {
2020-05-20 08:25:31 +00:00
const { conference } = state['features/base/conference'];
const { hideLobbyButton } = state['features/base/config'];
2020-05-20 08:25:31 +00:00
return {
_lobbyEnabled: state['features/lobby'].lobbyEnabled,
_visible: conference?.isLobbySupported() && isLocalParticipantModerator(state)
&& !hideLobbyButton && !isInBreakoutRoom(state)
2020-05-20 08:25:31 +00:00
};
}
export default translate(connect(mapStateToProps)(LobbySection));