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.

SharedVideoButton.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { getFeatureFlag, VIDEO_SHARE_BUTTON_ENABLED } from '../../../base/flags';
  4. import { translate } from '../../../base/i18n';
  5. import { IconShareVideo } from '../../../base/icons';
  6. import { getLocalParticipant } from '../../../base/participants';
  7. import { connect } from '../../../base/redux';
  8. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  9. import { toggleSharedVideo } from '../../actions.native';
  10. import { isSharingStatus } from '../../functions';
  11. /**
  12. * The type of the React {@code Component} props of {@link TileViewButton}.
  13. */
  14. type Props = AbstractButtonProps & {
  15. /**
  16. * Whether or not the button is disabled.
  17. */
  18. _isDisabled: boolean,
  19. /**
  20. * Whether or not the local participant is sharing a video.
  21. */
  22. _sharingVideo: boolean,
  23. /**
  24. * The redux {@code dispatch} function.
  25. */
  26. dispatch: Dispatch<any>
  27. };
  28. /**
  29. * Component that renders a toolbar button for toggling the tile layout view.
  30. *
  31. * @extends AbstractButton
  32. */
  33. class VideoShareButton extends AbstractButton<Props, *> {
  34. accessibilityLabel = 'toolbar.accessibilityLabel.sharedvideo';
  35. icon = IconShareVideo;
  36. label = 'toolbar.sharedvideo';
  37. toggledLabel = 'toolbar.stopSharedVideo';
  38. /**
  39. * Handles clicking / pressing the button.
  40. *
  41. * @override
  42. * @protected
  43. * @returns {void}
  44. */
  45. _handleClick() {
  46. this._doToggleSharedVideo();
  47. }
  48. /**
  49. * Indicates whether this button is in toggled state or not.
  50. *
  51. * @override
  52. * @protected
  53. * @returns {boolean}
  54. */
  55. _isToggled() {
  56. return this.props._sharingVideo;
  57. }
  58. /**
  59. * Indicates whether this button is disabled or not.
  60. *
  61. * @override
  62. * @protected
  63. * @returns {boolean}
  64. */
  65. _isDisabled() {
  66. return this.props._isDisabled;
  67. }
  68. /**
  69. * Dispatches an action to toggle video sharing.
  70. *
  71. * @private
  72. * @returns {void}
  73. */
  74. _doToggleSharedVideo() {
  75. this.props.dispatch(toggleSharedVideo());
  76. }
  77. }
  78. /**
  79. * Maps part of the Redux state to the props of this component.
  80. *
  81. * @param {Object} state - The Redux state.
  82. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  83. * @private
  84. * @returns {Props}
  85. */
  86. function _mapStateToProps(state, ownProps): Object {
  87. const { ownerId, status: sharedVideoStatus } = state['features/shared-video'];
  88. const localParticipantId = getLocalParticipant(state).id;
  89. const enabled = getFeatureFlag(state, VIDEO_SHARE_BUTTON_ENABLED, true);
  90. const { visible = enabled } = ownProps;
  91. if (ownerId !== localParticipantId) {
  92. return {
  93. _isDisabled: isSharingStatus(sharedVideoStatus),
  94. _sharingVideo: false,
  95. visible
  96. };
  97. }
  98. return {
  99. _isDisabled: false,
  100. _sharingVideo: isSharingStatus(sharedVideoStatus),
  101. visible
  102. };
  103. }
  104. export default translate(connect(_mapStateToProps)(VideoShareButton));