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.

TranscriptionSubtitles.web.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. /**
  5. * The type of the React {@code Component} props of
  6. * {@link TranscriptionSubtitles}.
  7. */
  8. type Props = {
  9. /**
  10. * Map of transcriptMessageID's with corresponding transcriptMessage.
  11. */
  12. _transcriptMessages: Map<string, Object>
  13. };
  14. /**
  15. * React {@code Component} which can display speech-to-text results from
  16. * Jigasi as subtitles.
  17. */
  18. class TranscriptionSubtitles extends Component<Props> {
  19. /**
  20. * Implements React's {@link Component#render()}.
  21. *
  22. * @inheritdoc
  23. * @returns {ReactElement}
  24. */
  25. render() {
  26. const paragraphs = [];
  27. for (const [ transcriptMessageID, transcriptMessage ]
  28. of this.props._transcriptMessages) {
  29. let text;
  30. if (transcriptMessage) {
  31. text = `${transcriptMessage.participantName}: `;
  32. if (transcriptMessage.final) {
  33. text += transcriptMessage.final;
  34. } else {
  35. const stable = transcriptMessage.stable || '';
  36. const unstable = transcriptMessage.unstable || '';
  37. text += stable + unstable;
  38. }
  39. paragraphs.push(
  40. <p key = { transcriptMessageID }> { text } </p>
  41. );
  42. }
  43. }
  44. return (
  45. <div className = 'transcription-subtitles' >
  46. { paragraphs }
  47. </div>
  48. );
  49. }
  50. }
  51. /**
  52. * Maps the transcriptionSubtitles in the Redux state to the associated
  53. * props of {@code TranscriptionSubtitles}.
  54. *
  55. * @param {Object} state - The Redux state.
  56. * @private
  57. * @returns {{
  58. * _transcriptMessages: Map
  59. * }}
  60. */
  61. function _mapStateToProps(state) {
  62. return {
  63. _transcriptMessages: state['features/subtitles'].transcriptMessages
  64. };
  65. }
  66. export default connect(_mapStateToProps)(TranscriptionSubtitles);