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.

ClosedCaptionButton.web.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { translate } from '../../base/i18n/index';
  5. import { ToolbarButton } from '../../toolbox/';
  6. import { dialTranscriber, stopTranscribing } from '../actions';
  7. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  8. /**
  9. * The type of the React {@code Component} props of {@link TranscribingLabel}.
  10. */
  11. type Props = {
  12. /**
  13. * Invoked to obtain translated strings.
  14. */
  15. t: Function,
  16. /**
  17. * Invoked to Dispatch an Action to the redux store.
  18. */
  19. dispatch: Function,
  20. /**
  21. * Boolean value indicating current transcribing status
  22. */
  23. _transcribing: boolean,
  24. /**
  25. * Boolean value indicating current dialing status
  26. */
  27. _dialing: boolean
  28. };
  29. /**
  30. * React Component for displaying a label when a transcriber is in the
  31. * conference.
  32. *
  33. * @extends Component
  34. */
  35. class ClosedCaptionButton extends Component<Props> {
  36. /**
  37. * Initializes a new {@code ClosedCaptionButton} instance.
  38. *
  39. * @param {Props} props - The read-only properties with which the new
  40. * instance is to be initialized.
  41. */
  42. constructor(props: Props) {
  43. super(props);
  44. // Bind event handler so it is only bound once for every instance.
  45. this._onToggleButton = this._onToggleButton.bind(this);
  46. }
  47. /**
  48. * Implements React's {@link Component#render()}.
  49. *
  50. * @inheritdoc
  51. * @returns {ReactElement}
  52. */
  53. render() {
  54. const { _dialing, _transcribing, t } = this.props;
  55. const iconClass = `icon-closed_caption ${_dialing || _transcribing
  56. ? 'toggled' : ''}`;
  57. return (
  58. <ToolbarButton
  59. accessibilityLabel
  60. = { t('toolbar.accessibilityLabel.cc') }
  61. iconName = { iconClass }
  62. onClick = { this._onToggleButton }
  63. tooltip = { t('transcribing.ccButtonTooltip') } />
  64. );
  65. }
  66. _onToggleButton: () => void;
  67. /**
  68. * Dispatch actions for starting or stopping transcription, based on
  69. * current state.
  70. *
  71. * @private
  72. * @returns {void}
  73. */
  74. _onToggleButton() {
  75. const { _transcribing, _dialing, dispatch } = this.props;
  76. sendAnalytics(createToolbarEvent(
  77. 'transcribing.ccButton',
  78. {
  79. 'is_transcribing': Boolean(_transcribing),
  80. 'is_dialing': Boolean(_dialing)
  81. }));
  82. if (_dialing) {
  83. return;
  84. }
  85. if (_transcribing) {
  86. dispatch(stopTranscribing());
  87. } else {
  88. dispatch(dialTranscriber());
  89. }
  90. }
  91. }
  92. /**
  93. * Maps (parts of) the Redux state to the associated props for the
  94. * {@code ClosedCaptionButton} component.
  95. *
  96. * @param {Object} state - The Redux state.
  97. * @private
  98. * @returns {{
  99. * }}
  100. */
  101. function _mapStateToProps(state) {
  102. const { isTranscribing, isDialing } = state['features/transcribing'];
  103. return {
  104. _transcribing: isTranscribing,
  105. _dialing: isDialing
  106. };
  107. }
  108. export default translate(connect(_mapStateToProps)(ClosedCaptionButton));