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 3.4KB

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