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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * Whether local participant is requesting to see subtitles
  15. */
  16. _requestingSubtitles: Boolean
  17. };
  18. /**
  19. * React {@code Component} which can display speech-to-text results from
  20. * Jigasi as subtitles.
  21. */
  22. class TranscriptionSubtitles extends Component<Props> {
  23. /**
  24. * Implements React's {@link Component#render()}.
  25. *
  26. * @inheritdoc
  27. * @returns {ReactElement}
  28. */
  29. render() {
  30. if (!this.props._requestingSubtitles
  31. || !this.props._transcriptMessages) {
  32. return null;
  33. }
  34. const paragraphs = [];
  35. for (const [ transcriptMessageID, transcriptMessage ]
  36. of this.props._transcriptMessages) {
  37. let text;
  38. if (transcriptMessage) {
  39. text = `${transcriptMessage.participantName}: `;
  40. if (transcriptMessage.final) {
  41. text += transcriptMessage.final;
  42. } else {
  43. const stable = transcriptMessage.stable || '';
  44. const unstable = transcriptMessage.unstable || '';
  45. text += stable + unstable;
  46. }
  47. paragraphs.push(
  48. <p key = { transcriptMessageID }>
  49. <span>{ text }</span>
  50. </p>
  51. );
  52. }
  53. }
  54. return (
  55. <div className = 'transcription-subtitles' >
  56. { paragraphs }
  57. </div>
  58. );
  59. }
  60. }
  61. /**
  62. * Maps the transcriptionSubtitles in the Redux state to the associated
  63. * props of {@code TranscriptionSubtitles}.
  64. *
  65. * @param {Object} state - The Redux state.
  66. * @private
  67. * @returns {{
  68. * _transcriptMessages: Map
  69. * }}
  70. */
  71. function _mapStateToProps(state) {
  72. const {
  73. _transcriptMessages,
  74. _requestingSubtitles
  75. } = state['features/subtitles'];
  76. return {
  77. _transcriptMessages,
  78. _requestingSubtitles
  79. };
  80. }
  81. export default connect(_mapStateToProps)(TranscriptionSubtitles);