2020-03-30 14:17:18 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2020-06-29 20:59:28 +00:00
|
|
|
import { isMobileBrowser } from '../../../base/environment/utils';
|
2020-03-30 14:17:18 +00:00
|
|
|
import { IconArrowDown } from '../../../base/icons';
|
2020-05-20 10:57:03 +00:00
|
|
|
import JitsiMeetJS from '../../../base/lib-jitsi-meet/_';
|
2020-03-30 14:17:18 +00:00
|
|
|
import { connect } from '../../../base/redux';
|
2020-07-24 12:14:33 +00:00
|
|
|
import { ToolboxButtonWithIcon } from '../../../base/toolbox/components';
|
2020-06-19 07:03:26 +00:00
|
|
|
import { getLocalJitsiVideoTrack } from '../../../base/tracks';
|
2020-04-07 07:14:23 +00:00
|
|
|
import { getMediaPermissionPromptVisibility } from '../../../overlay';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { toggleVideoSettings, VideoSettingsPopup } from '../../../settings';
|
|
|
|
import { isVideoSettingsButtonDisabled } from '../../functions';
|
|
|
|
import VideoMuteButton from '../VideoMuteButton';
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Click handler for the small icon. Opens video options.
|
|
|
|
*/
|
|
|
|
onVideoOptionsClick: Function,
|
|
|
|
|
2020-04-07 07:14:23 +00:00
|
|
|
/**
|
|
|
|
* Whether the permission prompt is visible or not.
|
|
|
|
* Useful for enabling the button on initial permission grant.
|
|
|
|
*/
|
|
|
|
permissionPromptVisibility: boolean,
|
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
/**
|
|
|
|
* Whether there is a video track or not.
|
|
|
|
*/
|
|
|
|
hasVideoTrack: 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.
|
2020-06-29 20:59:28 +00:00
|
|
|
* VideoSettings popup is currently disabled on mobile browsers
|
|
|
|
* as mobile devices do not support capture of more than one
|
|
|
|
* camera at a time.
|
2020-03-30 14:17:18 +00:00
|
|
|
*/
|
|
|
|
visible: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the app has video permissions or not.
|
|
|
|
*/
|
|
|
|
hasPermissions: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Button used for video & video settings.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
class VideoSettingsButton 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 VideoSettingsButton} 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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-19 07:03:26 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the settings icon is disabled.
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isIconDisabled() {
|
|
|
|
const { hasVideoTrack, isDisabled } = this.props;
|
|
|
|
|
|
|
|
return (!this.state.hasPermissions || isDisabled) && !hasVideoTrack;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
/**
|
|
|
|
* Updates device permissions.
|
|
|
|
*
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
async _updatePermissions() {
|
|
|
|
const hasPermissions = await JitsiMeetJS.mediaDevices.isDevicePermissionGranted(
|
|
|
|
'video',
|
|
|
|
);
|
|
|
|
|
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-06-19 07:03:26 +00:00
|
|
|
const { onVideoOptionsClick, visible } = this.props;
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
return visible ? (
|
|
|
|
<VideoSettingsPopup>
|
|
|
|
<ToolboxButtonWithIcon
|
|
|
|
icon = { IconArrowDown }
|
2020-06-19 07:03:26 +00:00
|
|
|
iconDisabled = { this._isIconDisabled() }
|
2020-03-30 14:17:18 +00:00
|
|
|
onIconClick = { onVideoOptionsClick }>
|
|
|
|
<VideoMuteButton />
|
|
|
|
</ToolboxButtonWithIcon>
|
|
|
|
</VideoSettingsPopup>
|
2020-06-29 20:59:28 +00:00
|
|
|
) : <VideoMuteButton />;
|
2020-03-30 14:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
2020-06-19 07:03:26 +00:00
|
|
|
hasVideoTrack: Boolean(getLocalJitsiVideoTrack(state)),
|
2020-04-16 10:47:10 +00:00
|
|
|
isDisabled: isVideoSettingsButtonDisabled(state),
|
2020-06-29 20:59:28 +00:00
|
|
|
permissionPromptVisibility: getMediaPermissionPromptVisibility(state),
|
|
|
|
visible: !isMobileBrowser()
|
2020-03-30 14:17:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
onVideoOptionsClick: toggleVideoSettings
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps,
|
|
|
|
)(VideoSettingsButton);
|