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

ScreenSharingIosButton.js 3.9KB

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