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.8KB

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