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.web.js 2.4KB

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