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

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