您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ScreenSharingIosButton.tsx 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import React from 'react';
  2. import { NativeModules, Platform, findNodeHandle } from 'react-native';
  3. import { ScreenCapturePickerView } from 'react-native-webrtc';
  4. import { connect } from 'react-redux';
  5. import { IReduxState } from '../../../app/types';
  6. import { IOS_SCREENSHARING_ENABLED } from '../../../base/flags/constants';
  7. import { getFeatureFlag } from '../../../base/flags/functions';
  8. import { translate } from '../../../base/i18n/functions';
  9. import { IconScreenshare } from '../../../base/icons/svg';
  10. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  11. import { isLocalVideoTrackDesktop } from '../../../base/tracks/functions.native';
  12. /**
  13. * The type of the React {@code Component} props of {@link ScreenSharingIosButton}.
  14. */
  15. interface IProps extends AbstractButtonProps {
  16. /**
  17. * True if the button needs to be disabled.
  18. */
  19. _disabled: boolean;
  20. /**
  21. * Whether video is currently muted or not.
  22. */
  23. _screensharing: boolean;
  24. }
  25. const styles = {
  26. screenCapturePickerView: {
  27. display: 'none'
  28. }
  29. };
  30. /**
  31. * An implementation of a button for toggling screen sharing on iOS.
  32. */
  33. class ScreenSharingIosButton extends AbstractButton<IProps> {
  34. _nativeComponent: React.Component<any, any> | null;
  35. accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
  36. icon = IconScreenshare;
  37. label = 'toolbar.startScreenSharing';
  38. toggledLabel = 'toolbar.stopScreenSharing';
  39. /**
  40. * Initializes a new {@code ScreenSharingIosButton} instance.
  41. *
  42. * @param {Object} props - The React {@code Component} props to initialize
  43. * the new {@code ScreenSharingIosButton} instance with.
  44. */
  45. constructor(props: IProps) {
  46. super(props);
  47. this._nativeComponent = null;
  48. // Bind event handlers so they are only bound once per instance.
  49. this._setNativeComponent = this._setNativeComponent.bind(this);
  50. }
  51. /**
  52. * Implements React's {@link Component#render()}.
  53. *
  54. * @inheritdoc
  55. * @returns {React$Node}
  56. */
  57. render() {
  58. return (
  59. <>
  60. { super.render() }
  61. <ScreenCapturePickerView
  62. ref = { this._setNativeComponent } // @ts-ignore
  63. style = { styles.screenCapturePickerView } />
  64. </>
  65. );
  66. }
  67. /**
  68. * Sets the internal reference to the React Component wrapping the
  69. * {@code RPSystemBroadcastPickerView} component.
  70. *
  71. * @param {ReactComponent} component - React Component.
  72. * @returns {void}
  73. */
  74. _setNativeComponent(component: React.Component<any, any> | null) {
  75. this._nativeComponent = component;
  76. }
  77. /**
  78. * Handles clicking / pressing the button.
  79. *
  80. * @override
  81. * @protected
  82. * @returns {void}
  83. */
  84. _handleClick() {
  85. const handle = findNodeHandle(this._nativeComponent);
  86. NativeModules.ScreenCapturePickerViewManager.show(handle);
  87. }
  88. /**
  89. * Returns a boolean value indicating if this button is disabled or not.
  90. *
  91. * @protected
  92. * @returns {boolean}
  93. */
  94. _isDisabled() {
  95. return this.props._disabled;
  96. }
  97. /**
  98. * Indicates whether this button is in toggled state or not.
  99. *
  100. * @override
  101. * @protected
  102. * @returns {boolean}
  103. */
  104. _isToggled() {
  105. return this.props._screensharing;
  106. }
  107. }
  108. /**
  109. * Maps (parts of) the redux state to the associated props for the
  110. * {@code ScreenSharingIosButton} component.
  111. *
  112. * @param {Object} state - The Redux state.
  113. * @private
  114. * @returns {{
  115. * _disabled: boolean,
  116. * }}
  117. */
  118. function _mapStateToProps(state: IReduxState) {
  119. const enabled = getFeatureFlag(state, IOS_SCREENSHARING_ENABLED, false);
  120. return {
  121. _screensharing: isLocalVideoTrackDesktop(state),
  122. // TODO: this should work on iOS 12 too, but our trick to show the picker doesn't work.
  123. visible: enabled
  124. && Platform.OS === 'ios'
  125. && Number.parseInt(Platform.Version.split('.')[0], 10) >= 14
  126. };
  127. }
  128. export default translate(connect(_mapStateToProps)(ScreenSharingIosButton));