You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScreenSharingIosButton.js 4.0KB

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