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

ScreenSharingIosButton.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // @flow
  2. import React from 'react';
  3. import { findNodeHandle, NativeModules, Platform } from 'react-native';
  4. import { ScreenCapturePickerView } from 'react-native-webrtc';
  5. import { getFeatureFlag, IOS_SCREENSHARING_ENABLED } from '../../../base/flags';
  6. import { translate } from '../../../base/i18n';
  7. import { IconShareDesktop } 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 = IconShareDesktop;
  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. * Sets the internal reference to the React Component wrapping the
  57. * {@code RPSystemBroadcastPickerView} component.
  58. *
  59. * @param {ReactComponent} component - React Component.
  60. * @returns {void}
  61. */
  62. _setNativeComponent(component) {
  63. this._nativeComponent = component;
  64. }
  65. /**
  66. * Handles clicking / pressing the button.
  67. *
  68. * @override
  69. * @protected
  70. * @returns {void}
  71. */
  72. _handleClick() {
  73. const handle = findNodeHandle(this._nativeComponent);
  74. NativeModules.ScreenCapturePickerViewManager.show(handle);
  75. }
  76. /**
  77. * Returns a boolean value indicating if this button is disabled or not.
  78. *
  79. * @protected
  80. * @returns {boolean}
  81. */
  82. _isDisabled() {
  83. return this.props._disabled;
  84. }
  85. /**
  86. * Indicates whether this button is in toggled state or not.
  87. *
  88. * @override
  89. * @protected
  90. * @returns {boolean}
  91. */
  92. _isToggled() {
  93. return this.props._screensharing;
  94. }
  95. /**
  96. * Helper function to be implemented by subclasses, which may return a
  97. * new React Element to be appended at the end of the button.
  98. *
  99. * @protected
  100. * @returns {ReactElement|null}
  101. */
  102. _getElementAfter() {
  103. return (
  104. <ScreenCapturePickerView
  105. ref = { this._setNativeComponent }
  106. style = { styles.screenCapturePickerView } />
  107. );
  108. }
  109. }
  110. /**
  111. * Maps (parts of) the redux state to the associated props for the
  112. * {@code ScreenSharingIosButton} component.
  113. *
  114. * @param {Object} state - The Redux state.
  115. * @private
  116. * @returns {{
  117. * _disabled: boolean,
  118. * }}
  119. */
  120. function _mapStateToProps(state): Object {
  121. const enabled = getFeatureFlag(state, IOS_SCREENSHARING_ENABLED, false);
  122. return {
  123. _screensharing: isLocalVideoTrackDesktop(state),
  124. // TODO: this should work on iOS 12 too, but our trick to show the picker doesn't work.
  125. visible: enabled && Platform.OS === 'ios' && Platform.Version.split('.')[0] >= 14
  126. };
  127. }
  128. export default translate(connect(_mapStateToProps)(ScreenSharingIosButton));