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.

Captions.tsx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React, { ReactElement } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState } from '../../../app/types';
  4. import { getLocalParticipant } from '../../../base/participants/functions';
  5. import { getLargeVideoParticipant } from '../../../large-video/functions';
  6. import { isLayoutTileView } from '../../../video-layout/functions.web';
  7. import {
  8. AbstractCaptions,
  9. type IAbstractCaptionsProps,
  10. _abstractMapStateToProps
  11. } from '../AbstractCaptions';
  12. interface IProps extends IAbstractCaptionsProps {
  13. /**
  14. * Whether the subtitles container is lifted above the invite box.
  15. */
  16. _isLifted: boolean | undefined;
  17. }
  18. /**
  19. * React {@code Component} which can display speech-to-text results from
  20. * Jigasi as subtitles.
  21. */
  22. class Captions extends AbstractCaptions<IProps> {
  23. /**
  24. * Renders the transcription text.
  25. *
  26. * @param {string} id - The ID of the transcript message from which the
  27. * {@code text} has been created.
  28. * @param {string} text - Subtitles text formatted with the participant's
  29. * name.
  30. * @protected
  31. * @returns {ReactElement} - The React element which displays the text.
  32. */
  33. _renderParagraph(id: string, text: string): ReactElement {
  34. return (
  35. <p key = { id }>
  36. <span>{ text }</span>
  37. </p>
  38. );
  39. }
  40. /**
  41. * Renders the subtitles container.
  42. *
  43. * @param {Array<ReactElement>} paragraphs - An array of elements created
  44. * for each subtitle using the {@link _renderParagraph} method.
  45. * @protected
  46. * @returns {ReactElement} - The subtitles container.
  47. */
  48. _renderSubtitlesContainer(paragraphs: Array<ReactElement>): ReactElement {
  49. const className = this.props._isLifted
  50. ? 'transcription-subtitles lifted'
  51. : 'transcription-subtitles';
  52. return (
  53. <div className = { className } >
  54. { paragraphs }
  55. </div>
  56. );
  57. }
  58. }
  59. /**
  60. * Maps (parts of) the redux state to the associated {@code }'s
  61. * props.
  62. *
  63. * @param {Object} state - The redux state.
  64. * @private
  65. * @returns {Object}
  66. */
  67. function mapStateToProps(state: IReduxState) {
  68. const isTileView = isLayoutTileView(state);
  69. const largeVideoParticipant = getLargeVideoParticipant(state);
  70. const localParticipant = getLocalParticipant(state);
  71. return {
  72. ..._abstractMapStateToProps(state),
  73. _isLifted: Boolean(largeVideoParticipant && largeVideoParticipant?.id !== localParticipant?.id && !isTileView)
  74. };
  75. }
  76. export default connect(mapStateToProps)(Captions);