2018-04-18 14:34:40 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2018-05-10 23:01:55 +00:00
|
|
|
import { translate } from '../../base/i18n';
|
2018-05-17 15:47:05 +00:00
|
|
|
import { isLocalParticipantModerator } from '../../base/participants';
|
2018-05-10 23:01:55 +00:00
|
|
|
import { AbstractButton } from '../../base/toolbox';
|
|
|
|
import type { AbstractButtonProps } from '../../base/toolbox';
|
2018-04-18 14:34:40 +00:00
|
|
|
|
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';
|
2018-04-18 14:34:40 +00:00
|
|
|
iconName = 'security';
|
2018-05-22 10:02:05 +00:00
|
|
|
label = 'dialog.lockRoom';
|
2018-04-18 14:34:40 +00:00
|
|
|
toggledIconName = 'security-locked';
|
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.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
2018-05-17 15:47:05 +00:00
|
|
|
* _localParticipantModerator: boolean,
|
|
|
|
* _locked: boolean
|
2018-04-18 14:34:40 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state): Object {
|
|
|
|
const { conference, locked } = state['features/base/conference'];
|
|
|
|
|
|
|
|
return {
|
2018-05-17 15:47:05 +00:00
|
|
|
_localParticipantModerator:
|
|
|
|
Boolean(conference && isLocalParticipantModerator(state)),
|
2018-04-18 14:34:40 +00:00
|
|
|
_locked: Boolean(conference && locked)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(RoomLockButton));
|