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.tsx 3.3KB

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