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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 { toggleRequestingSubtitles } 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. * Whether the local participant is currently requesting subtitles.
  22. */
  23. _requestingSubtitles: Boolean
  24. };
  25. /**
  26. * React Component for displaying a label when a transcriber is in the
  27. * conference.
  28. *
  29. * @extends Component
  30. */
  31. class ClosedCaptionButton extends Component<Props> {
  32. /**
  33. * Initializes a new {@code ClosedCaptionButton} instance.
  34. *
  35. * @param {Props} props - The read-only properties with which the new
  36. * instance is to be initialized.
  37. */
  38. constructor(props: Props) {
  39. super(props);
  40. // Bind event handler so it is only bound once for every instance.
  41. this._onToggleButton = this._onToggleButton.bind(this);
  42. }
  43. /**
  44. * Implements React's {@link Component#render()}.
  45. *
  46. * @inheritdoc
  47. * @returns {ReactElement}
  48. */
  49. render() {
  50. const { _requestingSubtitles, t } = this.props;
  51. const iconClass = `icon-closed_caption ${_requestingSubtitles
  52. ? 'toggled' : ''}`;
  53. return (
  54. <ToolbarButton
  55. accessibilityLabel
  56. = { t('toolbar.accessibilityLabel.cc') }
  57. iconName = { iconClass }
  58. onClick = { this._onToggleButton }
  59. tooltip = { t('transcribing.ccButtonTooltip') } />
  60. );
  61. }
  62. _onToggleButton: () => void;
  63. /**
  64. * Dispatch actions for starting or stopping transcription, based on
  65. * current state.
  66. *
  67. * @private
  68. * @returns {void}
  69. */
  70. _onToggleButton() {
  71. const { _requestingSubtitles, dispatch } = this.props;
  72. sendAnalytics(createToolbarEvent('transcribing.ccButton',
  73. {
  74. 'requesting_subtitles': Boolean(_requestingSubtitles)
  75. }));
  76. dispatch(toggleRequestingSubtitles());
  77. }
  78. }
  79. /**
  80. * Maps (parts of) the Redux state to the associated props for the
  81. * {@code ClosedCaptionButton} component.
  82. *
  83. * @param {Object} state - The Redux state.
  84. * @private
  85. * @returns {{
  86. * }}
  87. */
  88. function _mapStateToProps(state) {
  89. const { _requestingSubtitles } = state['features/subtitles'];
  90. return {
  91. _requestingSubtitles
  92. };
  93. }
  94. export default translate(connect(_mapStateToProps)(ClosedCaptionButton));