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.

AbstractClosedCaptionButton.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  3. import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox';
  4. import { toggleRequestingSubtitles } from '../actions';
  5. export type AbstractProps = AbstractButtonProps & {
  6. /**
  7. * Invoked to obtain translated strings.
  8. */
  9. t: Function,
  10. /**
  11. * Invoked to Dispatch an Action to the redux store.
  12. */
  13. dispatch: Function,
  14. /**
  15. * Whether the local participant is currently requesting subtitles.
  16. */
  17. _requestingSubtitles: Boolean
  18. };
  19. /**
  20. * The button component which starts/stops the transcription.
  21. */
  22. export class AbstractClosedCaptionButton
  23. extends AbstractButton<AbstractProps, *> {
  24. /**
  25. * Handles clicking / pressing the button.
  26. *
  27. * @override
  28. * @protected
  29. * @returns {void}
  30. */
  31. _handleClick() {
  32. const { _requestingSubtitles, dispatch } = this.props;
  33. sendAnalytics(createToolbarEvent('transcribing.ccButton',
  34. {
  35. 'requesting_subtitles': Boolean(_requestingSubtitles)
  36. }));
  37. dispatch(toggleRequestingSubtitles());
  38. }
  39. /**
  40. * Indicates whether this button is disabled or not.
  41. *
  42. * @override
  43. * @protected
  44. * @returns {boolean}
  45. */
  46. _isDisabled() {
  47. return false;
  48. }
  49. /**
  50. * Indicates whether this button is in toggled state or not.
  51. *
  52. * @override
  53. * @protected
  54. * @returns {boolean}
  55. */
  56. _isToggled() {
  57. return this.props._requestingSubtitles;
  58. }
  59. }
  60. /**
  61. * Maps (parts of) the redux state to the associated props for the
  62. * {@code AbstractClosedCaptionButton} component.
  63. *
  64. * @param {Object} state - The redux state.
  65. * @param {Object} ownProps - The properties explicitly passed to the component
  66. * instance.
  67. * @private
  68. * @returns {{
  69. * _requestingSubtitles: boolean,
  70. * visible: boolean
  71. * }}
  72. */
  73. export function _abstractMapStateToProps(state: Object, ownProps: Object) {
  74. const { _requestingSubtitles } = state['features/subtitles'];
  75. const { isGuest = true } = state['features/base/jwt'];
  76. const { transcribingEnabled } = state['features/base/config'];
  77. const { visible = Boolean(transcribingEnabled && !isGuest) } = ownProps;
  78. return {
  79. _requestingSubtitles,
  80. visible
  81. };
  82. }