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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { translate } from '../../base/i18n';
  4. import { IconShareVideo } from '../../base/icons';
  5. import { getLocalParticipant } from '../../base/participants';
  6. import { connect } from '../../base/redux';
  7. import { AbstractButton } from '../../base/toolbox';
  8. import type { AbstractButtonProps } from '../../base/toolbox';
  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. * @private
  82. * @returns {Props}
  83. */
  84. function _mapStateToProps(state): Object {
  85. const { ownerId, status: sharedVideoStatus } = state['features/youtube-player'];
  86. const localParticipantId = getLocalParticipant(state).id;
  87. if (ownerId !== localParticipantId) {
  88. return {
  89. _isDisabled: isSharingStatus(sharedVideoStatus),
  90. _sharingVideo: false };
  91. }
  92. return {
  93. _sharingVideo: isSharingStatus(sharedVideoStatus)
  94. };
  95. }
  96. /**
  97. * Checks if the status is one that is actually sharing the video - playing, pause or start.
  98. *
  99. * @param {string} status - The shared video status.
  100. * @private
  101. * @returns {boolean}
  102. */
  103. function isSharingStatus(status) {
  104. return [ 'playing', 'pause', 'start' ].includes(status);
  105. }
  106. export default translate(connect(_mapStateToProps)(VideoShareButton));