bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/screenshare/component.jsx
Anton Georgiev 2d991cb078
Merge pull request #7286 from KDSBrowne/2.2-issue-7279
Fix refPresentationContainer requestFullscreen is not a function
2019-05-22 14:52:18 -04:00

103 lines
2.4 KiB
JavaScript
Executable File

import React from 'react';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
import PropTypes from 'prop-types';
import _ from 'lodash';
import FullscreenButtonContainer from '../video-provider/fullscreen-button/container';
import { styles } from './styles';
const intlMessages = defineMessages({
screenShareLabel: {
id: 'app.screenshare.screenShareLabel',
description: 'screen share area element label',
},
});
class ScreenshareComponent extends React.Component {
constructor() {
super();
this.state = {
loaded: false,
};
this.onVideoLoad = this.onVideoLoad.bind(this);
}
componentDidMount() {
const { presenterScreenshareHasStarted } = this.props;
presenterScreenshareHasStarted();
}
componentWillReceiveProps(nextProps) {
const {
isPresenter, unshareScreen,
} = this.props;
if (isPresenter && !nextProps.isPresenter) {
unshareScreen();
}
}
componentWillUnmount() {
const {
presenterScreenshareHasEnded, unshareScreen,
} = this.props;
presenterScreenshareHasEnded();
unshareScreen();
}
onVideoLoad() {
this.setState({ loaded: true });
}
renderFullscreenButton() {
const { intl } = this.props;
const full = () => {
if (!this.videoTag) return;
this.videoTag.requestFullscreen();
};
return (
<FullscreenButtonContainer
handleFullscreen={full}
key={_.uniqueId('fullscreenButton-')}
elementName={intl.formatMessage(intlMessages.screenShareLabel)}
fullscreenRef={this.videoTag}
/>
);
}
render() {
const { loaded } = this.state;
return (
[!loaded ? (
<div
key={_.uniqueId('screenshareArea-')}
className={styles.connecting}
/>
) : null,
this.renderFullscreenButton(),
(
<video
id="screenshareVideo"
key="screenshareVideo"
style={{ maxHeight: '100%', width: '100%' }}
autoPlay
playsInline
onLoadedData={this.onVideoLoad}
ref={(ref) => { this.videoTag = ref; }}
/>
)]
);
}
}
export default injectIntl(ScreenshareComponent);
ScreenshareComponent.propTypes = {
intl: intlShape.isRequired,
isPresenter: PropTypes.bool.isRequired,
unshareScreen: PropTypes.func.isRequired,
presenterScreenshareHasEnded: PropTypes.func.isRequired,
presenterScreenshareHasStarted: PropTypes.func.isRequired,
};