bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/screenshare/component.jsx

102 lines
2.4 KiB
React
Raw Normal View History

import React from 'react';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
2019-02-08 01:47:28 +08:00
import PropTypes from 'prop-types';
import _ from 'lodash';
import FullscreenButton from '../video-provider/fullscreen-button/component';
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,
};
2018-05-15 22:56:53 +08:00
this.onVideoLoad = this.onVideoLoad.bind(this);
}
componentDidMount() {
2019-02-08 01:47:28 +08:00
const { presenterScreenshareHasStarted } = this.props;
presenterScreenshareHasStarted();
}
componentWillReceiveProps(nextProps) {
const {
isPresenter, unshareScreen,
} = this.props;
2019-02-08 01:47:28 +08:00
if (isPresenter && !nextProps.isPresenter) {
unshareScreen();
}
}
componentWillUnmount() {
const {
presenterScreenshareHasEnded, unshareScreen,
} = this.props;
2019-02-08 01:47:28 +08:00
presenterScreenshareHasEnded();
unshareScreen();
}
2018-05-15 22:56:53 +08:00
onVideoLoad() {
this.setState({ loaded: true });
}
renderFullscreenButton() {
const { intl } = this.props;
const full = () => {
if (!this.videoTag) return;
this.videoTag.requestFullscreen();
};
return (
<FullscreenButton
handleFullscreen={full}
key={_.uniqueId('fullscreenButton-')}
elementName={intl.formatMessage(intlMessages.screenShareLabel)}
/>
);
}
render() {
2019-02-08 01:47:28 +08:00
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,
2019-02-08 01:47:28 +08:00
isPresenter: PropTypes.bool.isRequired,
unshareScreen: PropTypes.func.isRequired,
presenterScreenshareHasEnded: PropTypes.func.isRequired,
presenterScreenshareHasStarted: PropTypes.func.isRequired,
};