jiti-meet/react/features/toolbox/components/native/RaiseHandButton.js

117 lines
3.0 KiB
JavaScript
Raw Normal View History

2019-03-27 13:47:19 +00:00
// @flow
import { type Dispatch } from 'redux';
import {
createToolbarEvent,
sendAnalytics
} from '../../../analytics';
2020-05-20 10:57:03 +00:00
import { RAISE_HAND_ENABLED, getFeatureFlag } from '../../../base/flags';
2019-03-27 13:47:19 +00:00
import { translate } from '../../../base/i18n';
2019-08-30 16:39:06 +00:00
import { IconRaisedHand } from '../../../base/icons';
2019-03-27 13:47:19 +00:00
import {
getLocalParticipant,
participantUpdated
} from '../../../base/participants';
import { connect } from '../../../base/redux';
import { AbstractButton } from '../../../base/toolbox';
import type { AbstractButtonProps } from '../../../base/toolbox';
/**
* The type of the React {@code Component} props of {@link RaiseHandButton}.
*/
type Props = AbstractButtonProps & {
/**
* The local participant.
*/
_localParticipant: Object,
/**
* Whether the participant raused their hand or not.
*/
_raisedHand: boolean,
/**
* The redux {@code dispatch} function.
*/
dispatch: Dispatch<any>
};
/**
* An implementation of a button to raise or lower hand.
*/
class RaiseHandButton extends AbstractButton<Props, *> {
accessibilityLabel = 'toolbar.accessibilityLabel.raiseHand';
2019-08-30 16:39:06 +00:00
icon = IconRaisedHand;
2019-03-27 13:47:19 +00:00
label = 'toolbar.raiseYourHand';
toggledLabel = 'toolbar.lowerYourHand';
/**
* Handles clicking / pressing the button.
*
* @override
* @protected
* @returns {void}
*/
_handleClick() {
this._toggleRaisedHand();
}
/**
* Indicates whether this button is in toggled state or not.
*
* @override
* @protected
* @returns {boolean}
*/
_isToggled() {
return this.props._raisedHand;
}
/**
* Toggles the rased hand status of the local participant.
*
* @returns {void}
*/
_toggleRaisedHand() {
const enable = !this.props._raisedHand;
sendAnalytics(createToolbarEvent('raise.hand', { enable }));
this.props.dispatch(participantUpdated({
// XXX Only the local participant is allowed to update without
// stating the JitsiConference instance (i.e. participant property
// `conference` for a remote participant) because the local
// participant is uniquely identified by the very fact that there is
// only one local participant.
id: this.props._localParticipant.id,
local: true,
raisedHand: enable
}));
}
}
/**
* Maps part of the Redux state to the props of this component.
*
* @param {Object} state - The Redux state.
* @param {Object} ownProps - The properties explicitly passed to the component instance.
2019-03-27 13:47:19 +00:00
* @private
* @returns {Props}
2019-03-27 13:47:19 +00:00
*/
function _mapStateToProps(state, ownProps): Object {
2019-03-27 13:47:19 +00:00
const _localParticipant = getLocalParticipant(state);
const enabled = getFeatureFlag(state, RAISE_HAND_ENABLED, true);
const { visible = enabled } = ownProps;
2019-03-27 13:47:19 +00:00
return {
_localParticipant,
_raisedHand: _localParticipant.raisedHand,
visible
2019-03-27 13:47:19 +00:00
};
}
export default translate(connect(_mapStateToProps)(RaiseHandButton));