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

VideoShareButton.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 } from '../../base/toolbox';
  9. import type { AbstractButtonProps } from '../../base/toolbox';
  10. import { toggleSharedVideo } from '../actions';
  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 YouTube 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 YouTube 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/youtube-player'];
  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. return {
  98. _sharingVideo: isSharingStatus(sharedVideoStatus),
  99. visible
  100. };
  101. }
  102. /**
  103. * Checks if the status is one that is actually sharing the video - playing, pause or start.
  104. *
  105. * @param {string} status - The shared video status.
  106. * @private
  107. * @returns {boolean}
  108. */
  109. function isSharingStatus(status) {
  110. return [ 'playing', 'pause', 'start' ].includes(status);
  111. }
  112. export default translate(connect(_mapStateToProps)(VideoShareButton));