123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import { Theme } from '@mui/material';
- import React, { ReactElement } from 'react';
- import { connect } from 'react-redux';
- import { withStyles } from 'tss-react/mui';
-
- import { IReduxState } from '../../../app/types';
- import { getLocalParticipant } from '../../../base/participants/functions';
- import { getVideospaceFloatingElementsBottomSpacing } from '../../../base/ui/functions.web';
- import { getStageParticipantNameLabelHeight } from '../../../display-name/components/web/styles';
- import { getLargeVideoParticipant } from '../../../large-video/functions';
- import { isLayoutTileView } from '../../../video-layout/functions.web';
- import { calculateSubtitlesFontSize } from '../../functions.web';
- import {
- AbstractCaptions,
- type IAbstractCaptionsProps,
- _abstractMapStateToProps
- } from '../AbstractCaptions';
-
- interface IProps extends IAbstractCaptionsProps {
-
- /**
- * The height of the visible area.
- */
- _clientHeight?: number;
-
- /**
- * Whether the subtitles container is lifted above the invite box.
- */
- _isLifted: boolean | undefined;
-
- /**
- * An object containing the CSS classes.
- */
- classes?: Partial<Record<keyof ReturnType<typeof styles>, string>>;
- }
-
-
- const styles = (theme: Theme, props: IProps) => {
- const { _isLifted = false, _clientHeight } = props;
- const fontSize = calculateSubtitlesFontSize(_clientHeight);
- const padding = Math.ceil(0.2 * fontSize);
-
- // Currently the subtitles position are not affected by the toolbar visibility.
- let bottom = getVideospaceFloatingElementsBottomSpacing(theme, true);
-
- // This is the case where we display the onstage participant display name
- // below the subtitles.
- if (_isLifted) {
- // 10px is the space between the onstage participant display name label and subtitles. We also need
- // to add the padding of the subtitles because it will decrease the gap between the label and subtitles.
- bottom += getStageParticipantNameLabelHeight(theme) + 10 + padding;
- }
-
- return {
- transcriptionSubtitles: {
- bottom,
- fontSize: `${fontSize}px`,
- left: '50%',
- maxWidth: '50vw',
- overflowWrap: 'break-word' as const,
- pointerEvents: 'none' as const,
- position: 'absolute' as const,
- textShadow: `
- 0px 0px 1px rgba(0,0,0,0.3),
- 0px 1px 1px rgba(0,0,0,0.3),
- 1px 0px 1px rgba(0,0,0,0.3),
- 0px 0px 1px rgba(0,0,0,0.3)`,
- transform: 'translateX(-50%)',
- zIndex: 7, // The popups are with z-index 8. This z-index has to be lower.
- lineHeight: 1.2,
-
- span: {
- color: '#fff',
- background: 'black',
-
- // without this when the text is wrapped on 2+ lines there will be a gap in the background:
- padding: `${padding}px 0px`
- }
- }
- };
- };
-
- /**
- * React {@code Component} which can display speech-to-text results from
- * Jigasi as subtitles.
- */
- class Captions extends AbstractCaptions<IProps> {
-
- /**
- * Renders the transcription text.
- *
- * @param {string} id - The ID of the transcript message from which the
- * {@code text} has been created.
- * @param {string} text - Subtitles text formatted with the participant's
- * name.
- * @protected
- * @returns {ReactElement} - The React element which displays the text.
- */
- _renderParagraph(id: string, text: string): ReactElement {
- return (
- <p key = { id }>
- <span>{ text }</span>
- </p>
- );
- }
-
- /**
- * Renders the subtitles container.
- *
- * @param {Array<ReactElement>} paragraphs - An array of elements created
- * for each subtitle using the {@link _renderParagraph} method.
- * @protected
- * @returns {ReactElement} - The subtitles container.
- */
- _renderSubtitlesContainer(paragraphs: Array<ReactElement>): ReactElement {
- const classes = withStyles.getClasses(this.props);
-
- return (
- <div className = { classes.transcriptionSubtitles } >
- { paragraphs }
- </div>
- );
- }
- }
-
- /**
- * Maps (parts of) the redux state to the associated {@code }'s
- * props.
- *
- * @param {Object} state - The redux state.
- * @private
- * @returns {Object}
- */
- function mapStateToProps(state: IReduxState) {
- const isTileView = isLayoutTileView(state);
- const largeVideoParticipant = getLargeVideoParticipant(state);
- const localParticipant = getLocalParticipant(state);
- const { clientHeight } = state['features/base/responsive-ui'];
-
- return {
- ..._abstractMapStateToProps(state),
- _isLifted: Boolean(largeVideoParticipant && largeVideoParticipant?.id !== localParticipant?.id && !isTileView),
- _clientHeight: clientHeight
- };
- }
-
- export default connect(mapStateToProps)(withStyles(Captions, styles));
|