bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/closed-captions/component.jsx

82 lines
2.0 KiB
React
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import styles from './styles.scss';
import { findDOMNode } from 'react-dom';
export default class ClosedCaptions extends React.Component {
constructor(props) {
super(props);
this.shouldScrollBottom = false;
}
renderCaptions(caption) {
2017-06-03 03:25:02 +08:00
const text = caption.captions;
const captionStyles = {
whiteSpace: 'pre-wrap',
wordWrap: 'break-word',
fontFamily: this.props.fontFamily,
fontSize: this.props.fontSize,
color: this.props.fontColor,
};
return (
<span
style={captionStyles}
dangerouslySetInnerHTML={{ __html: text }}
key={caption.index}
/>
);
}
componentDidMount() {
2017-09-07 03:36:52 +08:00
// to let the whiteboard know that the presentation area's size has changed
window.dispatchEvent(new Event('resize'));
}
componentWillUnmount() {
2017-09-07 03:36:52 +08:00
// to let the whiteboard know that the presentation area's size has changed
window.dispatchEvent(new Event('resize'));
}
componentWillUpdate() {
const node = findDOMNode(this.ccScrollArea);
// number 4 is for the border
// offset height includes the border, but scrollheight doesn't
this.shouldScrollBottom = node.scrollTop + node.offsetHeight - 4 === node.scrollHeight;
}
componentDidUpdate() {
if (this.shouldScrollBottom) {
const node = findDOMNode(this.ccScrollArea);
node.scrollTop = node.scrollHeight;
}
}
render() {
const {
locale,
captions,
backgroundColor,
} = this.props;
return (
<div disabled className={styles.ccbox}>
2016-12-21 07:54:39 +08:00
<div className={styles.title}>
2017-06-03 03:25:02 +08:00
<p> {locale || 'Locale is not selected'} </p>
2016-12-21 07:54:39 +08:00
</div>
2016-12-23 16:26:22 +08:00
<div
ref={(ref) => { this.ccScrollArea = ref; }}
2016-12-23 16:26:22 +08:00
className={styles.frame}
2017-06-03 03:25:02 +08:00
style={{ background: backgroundColor }}
>
{captions[locale] ? captions[locale].captions.map(caption => (
2016-12-21 07:54:39 +08:00
this.renderCaptions(caption)
)) : null }
</div>
</div>
);
}
}