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.ts 3.0KB

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