2020-03-30 14:17:18 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { IconArrowDown } from '../../../base/icons';
|
|
|
|
import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
|
|
|
|
import { connect } from '../../../base/redux';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { ToolboxButtonWithIcon } from '../../../base/toolbox';
|
2020-04-07 07:14:23 +00:00
|
|
|
import { getMediaPermissionPromptVisibility } from '../../../overlay';
|
2020-03-30 14:17:18 +00:00
|
|
|
import { AudioSettingsPopup, toggleAudioSettings } from '../../../settings';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { isAudioSettingsButtonDisabled } from '../../functions';
|
|
|
|
import AudioMuteButton from '../AudioMuteButton';
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler for the small icon. Opens audio options.
|
|
|
|
*/
|
|
|
|
onAudioOptionsClick: Function,
|
|
|
|
|
2020-04-07 07:14:23 +00:00
|
|
|
/**
|
|
|
|
* Whether the permission prompt is visible or not.
|
|
|
|
* Useful for enabling the button on permission grant.
|
|
|
|
*/
|
|
|
|
permissionPromptVisibility: boolean,
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
2020-04-16 10:47:10 +00:00
|
|
|
* If the button should be disabled.
|
2020-03-30 14:17:18 +00:00
|
|
|
*/
|
2020-04-16 10:47:10 +00:00
|
|
|
isDisabled: boolean,
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag controlling the visibility of the button.
|
|
|
|
*/
|
|
|
|
visible: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there are permissions for audio devices.
|
|
|
|
*/
|
|
|
|
hasPermissions: boolean,
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Button used for audio & audio settings.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
class AudioSettingsButton extends Component<Props, State> {
|
2020-04-16 10:47:10 +00:00
|
|
|
_isMounted: boolean;
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code AudioSettingsButton} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
this._isMounted = true;
|
2020-03-30 14:17:18 +00:00
|
|
|
this.state = {
|
|
|
|
hasPermissions: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates device permissions.
|
|
|
|
*
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
async _updatePermissions() {
|
|
|
|
const hasPermissions = await JitsiMeetJS.mediaDevices.isDevicePermissionGranted(
|
|
|
|
'audio',
|
|
|
|
);
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
this._isMounted && this.setState({
|
2020-03-30 14:17:18 +00:00
|
|
|
hasPermissions
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#componentDidMount}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
|
|
|
this._updatePermissions();
|
|
|
|
}
|
|
|
|
|
2020-04-07 07:14:23 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#componentDidUpdate}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (this.props.permissionPromptVisibility !== prevProps.permissionPromptVisibility) {
|
|
|
|
this._updatePermissions();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 10:47:10 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#componentWillUnmount}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
this._isMounted = false;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
2020-04-16 10:47:10 +00:00
|
|
|
const { isDisabled, onAudioOptionsClick, visible } = this.props;
|
|
|
|
const settingsDisabled = !this.state.hasPermissions || isDisabled;
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
return visible ? (
|
|
|
|
<AudioSettingsPopup>
|
|
|
|
<ToolboxButtonWithIcon
|
|
|
|
icon = { IconArrowDown }
|
|
|
|
iconDisabled = { settingsDisabled }
|
|
|
|
onIconClick = { onAudioOptionsClick }>
|
|
|
|
<AudioMuteButton />
|
|
|
|
</ToolboxButtonWithIcon>
|
|
|
|
</AudioSettingsPopup>
|
|
|
|
) : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
2020-04-16 10:47:10 +00:00
|
|
|
isDisabled: isAudioSettingsButtonDisabled(state),
|
2020-04-07 07:14:23 +00:00
|
|
|
permissionPromptVisibility: getMediaPermissionPromptVisibility(state)
|
2020-03-30 14:17:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
onAudioOptionsClick: toggleAudioSettings
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
|
|
|
)(AudioSettingsButton);
|