import React, { Component } from 'react'; import { translate } from '../../base/i18n'; const VIDEO_ERROR_CLASS = 'video-preview-has-error'; /** * React component for displaying video. This component defers to lib-jitsi-meet * logic for rendering the video. * * @extends Component */ class VideoInputPreview extends Component { /** * VideoInputPreview component's property types. * * @static */ static propTypes = { /** * An error message to display instead of a preview. Displaying an error * will take priority over displaying a video preview. */ error: React.PropTypes.string, /** * Invoked to obtain translated strings. */ t: React.PropTypes.func, /** * The JitsiLocalTrack to display. */ track: React.PropTypes.object }; /** * Initializes a new VideoInputPreview instance. * * @param {Object} props - The read-only React Component props with which * the new instance is to be initialized. */ constructor(props) { super(props); /** * The internal reference to the DOM/HTML element intended for showing * error messages. * * @private * @type {HTMLDivElement} */ this._errorElement = null; /** * The internal reference to topmost DOM/HTML element backing the React * {@code Component}. Accessed directly for toggling a classname to * indicate an error is present so styling can be changed to display it. * * @private * @type {HTMLDivElement} */ this._rootElement = null; /** * The internal reference to the DOM/HTML element intended for * displaying a video. This element may be an HTML video element or a * temasys video object. * * @private * @type {HTMLVideoElement|Object} */ this._videoElement = null; // Bind event handlers so they are only bound once for every instance. this._setErrorElement = this._setErrorElement.bind(this); this._setRootElement = this._setRootElement.bind(this); this._setVideoElement = this._setVideoElement.bind(this); } /** * Invokes the library for rendering the video on initial display. * * @inheritdoc * @returns {void} */ componentDidMount() { if (this.props.error) { this._updateErrorView(this.props.error); } else { this._attachTrack(this.props.track); } } /** * Remove any existing associations between the current previewed track and * the component's video element. * * @inheritdoc * @returns {void} */ componentWillUnmount() { this._detachTrack(this.props.track); } /** * Implements React's {@link Component#render()}. * * @inheritdoc * @returns {ReactElement} */ render() { return (