2021-03-05 15:33:53 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { findNodeHandle, NativeModules, Platform } from 'react-native';
|
|
|
|
import { ScreenCapturePickerView } from 'react-native-webrtc';
|
|
|
|
|
2021-04-07 13:28:26 +00:00
|
|
|
import { getFeatureFlag, IOS_SCREENSHARING_ENABLED } from '../../../base/flags';
|
2021-03-05 15:33:53 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { IconShareDesktop } from '../../../base/icons';
|
|
|
|
import { connect } from '../../../base/redux';
|
|
|
|
import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
|
|
|
|
import { isLocalVideoTrackDesktop } from '../../../base/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} props of {@link ScreenSharingIosButton}.
|
|
|
|
*/
|
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
2021-05-26 08:43:24 +00:00
|
|
|
/**
|
|
|
|
* True if the button needs to be disabled.
|
|
|
|
*/
|
|
|
|
_disabled: boolean,
|
|
|
|
|
2021-03-05 15:33:53 +00:00
|
|
|
/**
|
|
|
|
* Whether video is currently muted or not.
|
|
|
|
*/
|
|
|
|
_screensharing: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The redux {@code dispatch} function.
|
|
|
|
*/
|
|
|
|
dispatch: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
const styles = {
|
|
|
|
screenCapturePickerView: {
|
|
|
|
display: 'none'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of a button for toggling screen sharing on iOS.
|
|
|
|
*/
|
|
|
|
class ScreenSharingIosButton extends AbstractButton<Props, *> {
|
2021-11-04 21:10:43 +00:00
|
|
|
_nativeComponent: ?Object;
|
|
|
|
_setNativeComponent: Function;
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
|
|
|
|
icon = IconShareDesktop;
|
|
|
|
label = 'toolbar.startScreenSharing';
|
|
|
|
toggledLabel = 'toolbar.stopScreenSharing';
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/**
|
2021-03-05 15:33:53 +00:00
|
|
|
* Initializes a new {@code ScreenSharingIosButton} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The React {@code Component} props to initialize
|
|
|
|
* the new {@code ScreenSharingIosButton} instance with.
|
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
this._nativeComponent = null;
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
|
|
this._setNativeComponent = this._setNativeComponent.bind(this);
|
|
|
|
}
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/**
|
2021-03-05 15:33:53 +00:00
|
|
|
* Sets the internal reference to the React Component wrapping the
|
|
|
|
* {@code RPSystemBroadcastPickerView} component.
|
|
|
|
*
|
|
|
|
* @param {ReactComponent} component - React Component.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
_setNativeComponent(component) {
|
|
|
|
this._nativeComponent = component;
|
|
|
|
}
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/**
|
2021-03-05 15:33:53 +00:00
|
|
|
* Handles clicking / pressing the button.
|
|
|
|
*
|
|
|
|
* @override
|
|
|
|
* @protected
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
_handleClick() {
|
|
|
|
const handle = findNodeHandle(this._nativeComponent);
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
NativeModules.ScreenCapturePickerViewManager.show(handle);
|
|
|
|
}
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/**
|
2021-05-26 08:43:24 +00:00
|
|
|
* Returns a boolean value indicating if this button is disabled or not.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
_isDisabled() {
|
|
|
|
return this.props._disabled;
|
|
|
|
}
|
2021-05-26 08:43:24 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/**
|
2021-03-05 15:33:53 +00:00
|
|
|
* Indicates whether this button is in toggled state or not.
|
|
|
|
*
|
|
|
|
* @override
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
_isToggled() {
|
|
|
|
return this.props._screensharing;
|
|
|
|
}
|
2021-03-05 15:33:53 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
/**
|
2021-03-05 15:33:53 +00:00
|
|
|
* Helper function to be implemented by subclasses, which may return a
|
|
|
|
* new React Element to be appended at the end of the button.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {ReactElement|null}
|
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
_getElementAfter() {
|
|
|
|
return (
|
|
|
|
<ScreenCapturePickerView
|
|
|
|
ref = { this._setNativeComponent }
|
|
|
|
style = { styles.screenCapturePickerView } />
|
|
|
|
);
|
|
|
|
}
|
2021-03-05 15:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps (parts of) the redux state to the associated props for the
|
|
|
|
* {@code ScreenSharingIosButton} component.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* _disabled: boolean,
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state): Object {
|
2021-04-07 13:28:26 +00:00
|
|
|
const enabled = getFeatureFlag(state, IOS_SCREENSHARING_ENABLED, false);
|
|
|
|
|
2021-03-05 15:33:53 +00:00
|
|
|
return {
|
|
|
|
_screensharing: isLocalVideoTrackDesktop(state),
|
|
|
|
|
|
|
|
// TODO: this should work on iOS 12 too, but our trick to show the picker doesn't work.
|
2022-01-07 10:54:42 +00:00
|
|
|
visible: enabled
|
|
|
|
&& Platform.OS === 'ios'
|
|
|
|
&& Number.parseInt(Platform.Version.split('.')[0], 10) >= 14
|
2021-03-05 15:33:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(ScreenSharingIosButton));
|