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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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, handleClick } = this.props;
  36. if (handleClick) {
  37. handleClick();
  38. return;
  39. }
  40. sendAnalytics(createToolbarEvent('transcribing.ccButton',
  41. {
  42. 'requesting_subtitles': Boolean(_requestingSubtitles)
  43. }));
  44. const dialogShown = await dispatch(maybeShowPremiumFeatureDialog(FEATURES.RECORDING));
  45. if (!dialogShown) {
  46. dispatch(toggleRequestingSubtitles());
  47. }
  48. }
  49. /**
  50. * Indicates whether this button is disabled or not.
  51. *
  52. * @override
  53. * @protected
  54. * @returns {boolean}
  55. */
  56. _isDisabled() {
  57. return false;
  58. }
  59. /**
  60. * Indicates whether this button is in toggled state or not.
  61. *
  62. * @override
  63. * @protected
  64. * @returns {boolean}
  65. */
  66. _isToggled() {
  67. return this.props._requestingSubtitles;
  68. }
  69. }
  70. /**
  71. * Maps (parts of) the redux state to the associated props for the
  72. * {@code AbstractClosedCaptionButton} component.
  73. *
  74. * @param {Object} state - The redux state.
  75. * @param {Object} ownProps - The properties explicitly passed to the component
  76. * instance.
  77. * @private
  78. * @returns {{
  79. * _requestingSubtitles: boolean,
  80. * visible: boolean
  81. * }}
  82. */
  83. export function _abstractMapStateToProps(state: Object, ownProps: Object) {
  84. const { _requestingSubtitles } = state['features/subtitles'];
  85. const { transcribingEnabled } = state['features/base/config'];
  86. const { isTranscribing } = state['features/transcribing'];
  87. // if the participant is moderator, it can enable transcriptions and if
  88. // transcriptions are already started for the meeting, guests can just show them
  89. const { visible = Boolean(transcribingEnabled
  90. && (isLocalParticipantModerator(state) || isTranscribing)) } = ownProps;
  91. return {
  92. _requestingSubtitles,
  93. visible
  94. };
  95. }