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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { translate } from '../../../base/i18n';
  4. import { IconShareVideo } from '../../../base/icons';
  5. import { connect } from '../../../base/redux';
  6. import {
  7. AbstractButton,
  8. type AbstractButtonProps
  9. } from '../../../base/toolbox/components';
  10. import { toggleSharedVideo } from '../../actions.any';
  11. import { isSharingStatus } from '../../functions';
  12. type Props = AbstractButtonProps & {
  13. /**
  14. * The redux {@code dispatch} function.
  15. */
  16. dispatch: Dispatch<any>,
  17. /**
  18. * Whether or not the button is disabled.
  19. */
  20. _isDisabled: boolean,
  21. /**
  22. * Whether or not the local participant is sharing a video.
  23. */
  24. _sharingVideo: boolean
  25. };
  26. /**
  27. * Implements an {@link AbstractButton} to open the user documentation in a new window.
  28. */
  29. class SharedVideoButton extends AbstractButton<Props, *> {
  30. accessibilityLabel = 'toolbar.accessibilityLabel.sharedvideo';
  31. icon = IconShareVideo;
  32. label = 'toolbar.sharedvideo';
  33. toggledLabel = 'toolbar.stopSharedVideo';
  34. /**
  35. * Dynamically retrieves tooltip based on sharing state.
  36. */
  37. get tooltip() {
  38. if (this._isToggled()) {
  39. return 'toolbar.stopSharedVideo';
  40. }
  41. return 'toolbar.sharedvideo';
  42. }
  43. /**
  44. * Required by linter due to AbstractButton overwritten prop being writable.
  45. *
  46. * @param {string} value - The value.
  47. */
  48. set tooltip(value) {
  49. return value;
  50. }
  51. /**
  52. * Handles clicking / pressing the button, and opens a new dialog.
  53. *
  54. * @private
  55. * @returns {void}
  56. */
  57. _handleClick() {
  58. const { handleClick } = this.props;
  59. if (handleClick) {
  60. handleClick();
  61. return;
  62. }
  63. this._doToggleSharedVideo();
  64. }
  65. /**
  66. * Indicates whether this button is in toggled state or not.
  67. *
  68. * @override
  69. * @protected
  70. * @returns {boolean}
  71. */
  72. _isToggled() {
  73. return this.props._sharingVideo;
  74. }
  75. /**
  76. * Indicates whether this button is disabled or not.
  77. *
  78. * @override
  79. * @protected
  80. * @returns {boolean}
  81. */
  82. _isDisabled() {
  83. return this.props._isDisabled;
  84. }
  85. /**
  86. * Dispatches an action to toggle video sharing.
  87. *
  88. * @private
  89. * @returns {void}
  90. */
  91. _doToggleSharedVideo() {
  92. this.props.dispatch(toggleSharedVideo());
  93. }
  94. }
  95. /**
  96. * Maps part of the Redux state to the props of this component.
  97. *
  98. * @param {Object} state - The Redux state.
  99. * @private
  100. * @returns {Props}
  101. */
  102. function _mapStateToProps(state): Object {
  103. const {
  104. disabled: sharedVideoBtnDisabled,
  105. status: sharedVideoStatus
  106. } = state['features/shared-video'];
  107. return {
  108. _isDisabled: sharedVideoBtnDisabled,
  109. _sharingVideo: isSharingStatus(sharedVideoStatus)
  110. };
  111. }
  112. export default translate(connect(_mapStateToProps)(SharedVideoButton));