2018-04-18 14:34:40 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-04-29 07:35:18 +00:00
|
|
|
import { MEETING_PASSWORD_ENABLED, getFeatureFlag } from '../../base/flags';
|
2018-05-10 23:01:55 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2019-08-30 16:39:06 +00:00
|
|
|
import { IconRoomLock, IconRoomUnlock } from '../../base/icons';
|
2018-05-17 15:47:05 +00:00
|
|
|
import { isLocalParticipantModerator } from '../../base/participants';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2020-07-24 12:14:33 +00:00
|
|
|
import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
|
2018-05-17 15:47:05 +00:00
|
|
|
import { beginRoomLockRequest, unlockRoom } from '../actions';
|
2018-04-18 14:34:40 +00:00
|
|
|
|
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
|
|
|
/**
|
2018-05-17 15:47:05 +00:00
|
|
|
* Whether the current local participant is a moderator, therefore is
|
|
|
|
* allowed to lock or unlock the conference.
|
2018-04-18 14:34:40 +00:00
|
|
|
*/
|
2018-05-17 15:47:05 +00:00
|
|
|
_localParticipantModerator: boolean,
|
2018-04-18 14:34:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the current conference is locked or not.
|
|
|
|
*/
|
|
|
|
_locked: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Function
|
2018-05-10 23:01:55 +00:00
|
|
|
};
|
2018-04-18 14:34:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of a button for locking / unlocking a room.
|
|
|
|
*/
|
|
|
|
class RoomLockButton extends AbstractButton<Props, *> {
|
2018-06-07 20:32:18 +00:00
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.lockRoom';
|
2019-08-30 16:39:06 +00:00
|
|
|
icon = IconRoomLock;
|
2018-05-22 10:02:05 +00:00
|
|
|
label = 'dialog.lockRoom';
|
2019-08-30 16:39:06 +00:00
|
|
|
toggledIcon = IconRoomUnlock;
|
2018-05-22 10:02:05 +00:00
|
|
|
toggledLabel = 'dialog.unlockRoom';
|
2018-04-18 14:34:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button.
|
|
|
|
*
|
2018-05-11 02:10:26 +00:00
|
|
|
* @override
|
|
|
|
* @protected
|
2018-04-18 14:34:40 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_handleClick() {
|
2018-05-17 15:47:05 +00:00
|
|
|
const { dispatch, _locked } = this.props;
|
|
|
|
|
|
|
|
if (_locked) {
|
|
|
|
dispatch(unlockRoom());
|
|
|
|
} else {
|
|
|
|
dispatch(beginRoomLockRequest());
|
|
|
|
}
|
2018-04-18 14:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether this button is disabled or not.
|
|
|
|
*
|
|
|
|
* @override
|
2018-05-11 02:10:26 +00:00
|
|
|
* @protected
|
2018-04-18 14:34:40 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isDisabled() {
|
2018-05-17 15:47:05 +00:00
|
|
|
return !this.props._localParticipantModerator;
|
2018-04-18 14:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether this button is in toggled state or not.
|
|
|
|
*
|
|
|
|
* @override
|
2018-05-11 02:10:26 +00:00
|
|
|
* @protected
|
2018-04-18 14:34:40 +00:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isToggled() {
|
|
|
|
return this.props._locked;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated props for the
|
|
|
|
* {@code RoomLockButton} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
2020-04-29 07:35:18 +00:00
|
|
|
* @param {Object} ownProps - The properties explicitly passed to the component instance.
|
2018-04-18 14:34:40 +00:00
|
|
|
* @private
|
2020-04-29 07:35:18 +00:00
|
|
|
* @returns {Props}
|
2018-04-18 14:34:40 +00:00
|
|
|
*/
|
2020-04-29 07:35:18 +00:00
|
|
|
function _mapStateToProps(state, ownProps): Object {
|
2018-04-18 14:34:40 +00:00
|
|
|
const { conference, locked } = state['features/base/conference'];
|
2020-04-29 07:35:18 +00:00
|
|
|
const enabled = getFeatureFlag(state, MEETING_PASSWORD_ENABLED, true);
|
|
|
|
const { visible = enabled } = ownProps;
|
2018-04-18 14:34:40 +00:00
|
|
|
|
|
|
|
return {
|
2020-04-29 07:35:18 +00:00
|
|
|
_localParticipantModerator: Boolean(conference && isLocalParticipantModerator(state)),
|
|
|
|
_locked: Boolean(conference && locked),
|
|
|
|
visible
|
2018-04-18 14:34:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(RoomLockButton));
|