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

324 lines
11 KiB
React
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
import WhiteboardOverlayContainer from '/imports/ui/components/whiteboard/whiteboard-overlay/container';
2017-04-19 08:54:51 +08:00
import WhiteboardToolbarContainer from '/imports/ui/components/whiteboard/whiteboard-toolbar/container';
import PollingContainer from '/imports/ui/components/polling/container';
2017-08-15 08:15:11 +08:00
import CursorWrapperContainer from './cursor/cursor-wrapper-container/container';
2017-07-27 20:35:55 +08:00
import AnnotationGroupContainer from '../whiteboard/annotation-group/container';
import PresentationToolbarContainer from './presentation-toolbar/container';
import PresentationOverlayContainer from './presentation-overlay/container';
import Slide from './slide/component';
import styles from './styles.scss';
2017-02-17 05:11:46 +08:00
export default class PresentationArea extends React.Component {
constructor() {
super();
this.state = {
2017-09-18 09:58:37 +08:00
presentationWidth: 0,
presentationHeight: 0,
showSlide: false,
};
this.getSvgRef = this.getSvgRef.bind(this);
}
componentDidMount() {
// adding an event listener to scale the whiteboard on 'resize' events sent by chat/userlist etc
window.addEventListener('resize', () => {
setTimeout(this.handleResize.bind(this), 0);
});
2017-09-18 09:58:37 +08:00
this.getInitialPresentationSizes();
}
componentWillUnmount() {
2017-09-06 09:36:15 +08:00
window.removeEventListener('resize', () => {
setTimeout(this.handleResize.bind(this), 0);
});
}
// returns a ref to the svg element, which is required by a WhiteboardOverlay
// to transform screen coordinates to svg coordinate system
getSvgRef() {
return this.svggroup;
}
2017-09-18 09:58:37 +08:00
getPresentationSizesAvailable() {
const { refPresentationArea, refWhiteboardArea } = this;
const presentationSizes = {};
2017-09-18 09:58:37 +08:00
if (refPresentationArea && refWhiteboardArea) {
// By default presentation sizes are equal to the sizes of the refPresentationArea
// direct parent of the svg wrapper
let clientHeight = refPresentationArea.clientHeight;
let clientWidth = refPresentationArea.clientWidth;
// if a user is a presenter - this means there is a whiteboard toolbar on the right
// and we have to get the width/height of the refWhiteboardArea
// (inner hidden div with absolute position)
if (this.props.userIsPresenter) {
2017-09-18 09:58:37 +08:00
clientHeight = refWhiteboardArea.clientHeight;
clientWidth = refWhiteboardArea.clientWidth;
}
2017-09-18 09:58:37 +08:00
presentationSizes.presentationHeight = clientHeight;
presentationSizes.presentationWidth = clientWidth;
2017-09-06 09:36:15 +08:00
}
2017-09-18 09:58:37 +08:00
return presentationSizes;
2017-09-06 09:36:15 +08:00
}
2017-09-18 09:58:37 +08:00
getInitialPresentationSizes() {
// determining the presentationWidth and presentationHeight (available space for the svg)
// on the initial load
const presentationSizes = this.getPresentationSizesAvailable();
if (Object.keys(presentationSizes).length > 0) {
// setting the state of the available space for the svg
2017-09-06 09:36:15 +08:00
// and set the showSlide to true to start rendering the slide
2017-09-18 09:58:37 +08:00
this.setState(
{
presentationHeight: presentationSizes.presentationHeight,
presentationWidth: presentationSizes.presentationWidth,
showSlide: true,
},
);
2017-09-06 09:36:15 +08:00
}
}
handleResize() {
2017-09-18 09:58:37 +08:00
const presentationSizes = this.getPresentationSizesAvailable();
if (Object.keys(presentationSizes).length > 0) {
// updating the size of the space available for the slide
2017-09-18 09:58:37 +08:00
this.setState(presentationSizes);
}
}
calculateSize() {
const originalWidth = this.props.currentSlide.width;
const originalHeight = this.props.currentSlide.height;
2017-09-18 09:58:37 +08:00
const { presentationHeight, presentationWidth } = this.state;
let adjustedWidth;
let adjustedHeight;
// Slide has a portrait orientation
if (originalWidth <= originalHeight) {
2017-09-18 09:58:37 +08:00
adjustedWidth = (presentationHeight * originalWidth) / originalHeight;
if (presentationWidth < adjustedWidth) {
adjustedHeight = (presentationHeight * presentationWidth) / adjustedWidth;
adjustedWidth = presentationWidth;
} else {
2017-09-18 09:58:37 +08:00
adjustedHeight = presentationHeight;
}
// Slide has a landscape orientation
} else {
2017-09-18 09:58:37 +08:00
adjustedHeight = (presentationWidth * originalHeight) / originalWidth;
if (presentationHeight < adjustedHeight) {
adjustedWidth = (presentationWidth * presentationHeight) / adjustedHeight;
adjustedHeight = presentationHeight;
} else {
2017-09-18 09:58:37 +08:00
adjustedWidth = presentationWidth;
}
}
return {
width: adjustedWidth,
height: adjustedHeight,
};
}
// renders the whole presentation area
2017-02-17 05:11:46 +08:00
renderPresentationArea() {
// sometimes tomcat publishes the slide url, but the actual file is not accessible (why?)
if (this.props.currentSlide &&
this.props.currentSlide.width &&
this.props.currentSlide.height) {
// to control the size of the svg wrapper manually
// and adjust cursor's thickness, so that svg didn't scale it automatically
const adjustedSizes = this.calculateSize();
2016-07-27 04:56:43 +08:00
// a reference to the slide object
const slideObj = this.props.currentSlide;
2017-09-18 09:58:37 +08:00
// svgWidth and svgHeight are needed to set the svg's coordinate system
const svgWidth = slideObj.width;
const svgHeight = slideObj.height;
// calculating viewBox and offsets for the current presentation
const x = ((-slideObj.xOffset * 2) * svgWidth) / 100;
const y = ((-slideObj.yOffset * 2) * svgHeight) / 100;
const viewBoxWidth = (svgWidth * slideObj.widthRatio) / 100;
const viewBoxHeight = (svgHeight * slideObj.heightRatio) / 100;
// Uri for the slide
const imageUri = this.props.currentSlide.svgUri || this.props.currentSlide.pngUri;
return (
<div
style={{
width: adjustedSizes.width,
height: adjustedSizes.height,
WebkitTransition: 'width 0.2s', /* Safari */
transition: 'width 0.2s',
2017-06-03 03:25:02 +08:00
}}
>
<CSSTransitionGroup
transitionName={{
enter: styles.enter,
enterActive: styles.enterActive,
appear: styles.appear,
appearActive: styles.appearActive,
}}
transitionAppear
transitionEnter
transitionLeave={false}
transitionAppearTimeout={400}
transitionEnterTimeout={400}
transitionLeaveTimeout={400}
>
<svg
width={svgWidth}
height={svgHeight}
ref={(ref) => { if (ref != null) { this.svggroup = ref; } }}
viewBox={`${x} ${y} ${viewBoxWidth} ${viewBoxHeight}`}
version="1.1"
xmlns="http://www.w3.org/2000/svg"
className={styles.svgStyles}
key={slideObj.id}
>
<defs>
<clipPath id="viewBox">
<rect x={x} y={y} width="100%" height="100%" fill="none" />
</clipPath>
</defs>
<g clipPath="url(#viewBox)">
<Slide
id="slideComponent"
imageUri={imageUri}
svgWidth={svgWidth}
svgHeight={svgHeight}
/>
<AnnotationGroupContainer
width={svgWidth}
height={svgHeight}
whiteboardId={slideObj.id}
/>
2017-08-15 08:15:11 +08:00
<CursorWrapperContainer
2017-07-25 01:50:44 +08:00
widthRatio={slideObj.widthRatio}
physicalWidthRatio={adjustedSizes.width / svgWidth}
slideWidth={svgWidth}
slideHeight={svgHeight}
/>
</g>
{this.props.userIsPresenter || this.props.multiUser ?
<PresentationOverlayContainer
slideWidth={svgWidth}
slideHeight={svgHeight}
getSvgRef={this.getSvgRef}
>
<WhiteboardOverlayContainer
getSvgRef={this.getSvgRef}
whiteboardId={slideObj.id}
slideWidth={svgWidth}
slideHeight={svgHeight}
viewBoxX={x}
viewBoxY={y}
viewBoxWidth={viewBoxWidth}
viewBoxHeight={viewBoxHeight}
physicalSlideWidth={(adjustedSizes.width / slideObj.widthRatio) * 100}
physicalSlideHeight={(adjustedSizes.height / slideObj.heightRatio) * 100}
/>
</PresentationOverlayContainer>
: null }
</svg>
</CSSTransitionGroup>
</div>
);
}
2017-06-03 03:25:02 +08:00
return null;
}
renderPresentationToolbar() {
2016-08-06 02:39:24 +08:00
if (this.props.currentSlide) {
return (
<PresentationToolbarContainer
2017-07-25 01:50:44 +08:00
currentSlideNum={this.props.currentSlide.num}
2016-08-06 02:39:24 +08:00
presentationId={this.props.currentSlide.presentationId}
/>
);
}
2017-06-03 03:25:02 +08:00
return null;
2016-08-06 02:39:24 +08:00
}
2017-04-19 08:54:51 +08:00
renderWhiteboardToolbar() {
if (this.props.currentSlide) {
const adjustedSizes = this.calculateSize();
2017-04-19 08:54:51 +08:00
return (
<WhiteboardToolbarContainer
whiteboardId={this.props.currentSlide.id}
height={adjustedSizes.height}
/>
);
}
return null;
2017-04-19 08:54:51 +08:00
}
render() {
return (
2017-02-17 05:11:46 +08:00
<div className={styles.presentationContainer}>
<div
2017-09-18 09:58:37 +08:00
ref={(ref) => { this.refPresentationArea = ref; }}
className={styles.presentationArea}
>
<div
2017-09-18 09:58:37 +08:00
ref={(ref) => { this.refWhiteboardArea = ref; }}
className={styles.whiteboardSizeAvailable}
/>
{this.state.showSlide ?
this.renderPresentationArea()
: null }
{this.props.userIsPresenter || this.props.multiUser ?
2017-04-19 08:54:51 +08:00
this.renderWhiteboardToolbar()
: null }
</div>
2016-06-30 06:00:06 +08:00
<PollingContainer />
{this.renderPresentationToolbar()}
</div>
);
}
}
PresentationArea.propTypes = {
// Defines a boolean value to detect whether a current user is a presenter
userIsPresenter: PropTypes.bool.isRequired,
currentSlide: PropTypes.shape({
// TODO don't need meetingId here
meetingId: PropTypes.string,
presentationId: PropTypes.string.isRequired,
current: PropTypes.bool.isRequired,
height: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
heightRatio: PropTypes.number.isRequired,
widthRatio: PropTypes.number.isRequired,
xOffset: PropTypes.number.isRequired,
yOffset: PropTypes.number.isRequired,
num: PropTypes.number.isRequired,
id: PropTypes.string.isRequired,
svgUri: PropTypes.string,
pngUri: PropTypes.string,
// TODO we don't use any of thefollowing uris here
swfUri: PropTypes.string.isRequired,
thumbUri: PropTypes.string.isRequired,
txtUri: PropTypes.string.isRequired,
}),
2017-08-15 08:15:11 +08:00
// current multi-user status
multiUser: PropTypes.bool.isRequired,
};
PresentationArea.defaultProps = {
currentSlide: undefined,
};