2018-04-18 14:34:40 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-07-21 09:13:24 +00:00
|
|
|
import { NativeModules, Platform } from 'react-native';
|
2020-04-15 07:36:40 +00:00
|
|
|
|
2022-11-08 15:25:36 +00:00
|
|
|
import { PIP_ENABLED, PIP_WHILE_SCREEN_SHARING_ENABLED, getFeatureFlag } from '../../../base/flags';
|
2018-05-10 23:01:55 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
2022-11-08 10:24:32 +00:00
|
|
|
import { IconArrowDown } from '../../../base/icons';
|
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';
|
2020-11-04 08:32:06 +00:00
|
|
|
import { isLocalVideoTrackDesktop } from '../../../base/tracks/functions';
|
2018-05-10 23:01:55 +00:00
|
|
|
import { enterPictureInPicture } from '../actions';
|
2018-04-18 14:34:40 +00:00
|
|
|
|
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether Picture-in-Picture is enabled or not.
|
|
|
|
*/
|
|
|
|
_enabled: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of a button for entering Picture-in-Picture mode.
|
|
|
|
*/
|
|
|
|
class PictureInPictureButton extends AbstractButton<Props, *> {
|
2018-06-07 20:32:18 +00:00
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.pip';
|
2022-11-08 10:24:32 +00:00
|
|
|
icon = IconArrowDown;
|
2018-04-18 14:34:40 +00:00
|
|
|
label = 'toolbar.pip';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button.
|
|
|
|
*
|
2018-05-11 02:10:26 +00:00
|
|
|
* @protected
|
2018-04-18 14:34:40 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_handleClick() {
|
|
|
|
this.props.dispatch(enterPictureInPicture());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
2018-05-11 02:10:26 +00:00
|
|
|
* @returns {React$Node}
|
2018-04-18 14:34:40 +00:00
|
|
|
*/
|
|
|
|
render() {
|
2018-05-11 02:10:26 +00:00
|
|
|
return this.props._enabled ? super.render() : null;
|
2018-04-18 14:34:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated props for the
|
|
|
|
* {@code PictureInPictureButton} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* _enabled: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state): Object {
|
2022-11-08 15:25:36 +00:00
|
|
|
const pipEnabled = Boolean(getFeatureFlag(state, PIP_ENABLED));
|
|
|
|
const pipWhileScreenSharingEnabled = getFeatureFlag(state, PIP_WHILE_SCREEN_SHARING_ENABLED, false);
|
|
|
|
|
|
|
|
let enabled = pipEnabled && (!isLocalVideoTrackDesktop(state) || pipWhileScreenSharingEnabled);
|
2020-04-15 07:36:40 +00:00
|
|
|
|
2020-07-21 09:13:24 +00:00
|
|
|
// Override flag for Android, since it might be unsupported.
|
|
|
|
if (Platform.OS === 'android' && !NativeModules.PictureInPicture.SUPPORTED) {
|
2020-04-15 07:36:40 +00:00
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
|
2018-04-18 14:34:40 +00:00
|
|
|
return {
|
2020-04-15 07:36:40 +00:00
|
|
|
_enabled: enabled
|
2018-04-18 14:34:40 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(PictureInPictureButton));
|