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.

VideoShareButton.js 3.2KB

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