2017-06-04 10:40:14 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-06-05 07:20:38 +08:00
|
|
|
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
|
2017-07-29 08:29:40 +08:00
|
|
|
import ShapeGroupContainer from '/imports/ui/components/whiteboard/shape-group/container';
|
2017-05-02 05:34:24 +08:00
|
|
|
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';
|
2017-07-29 08:29:40 +08:00
|
|
|
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-29 08:29:40 +08:00
|
|
|
import PresentationToolbarContainer from './presentation-toolbar/container';
|
|
|
|
import PresentationOverlayContainer from './presentation-overlay/container';
|
|
|
|
import Slide from './slide/component';
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2016-05-31 06:07:02 +08:00
|
|
|
|
2017-02-17 05:11:46 +08:00
|
|
|
export default class PresentationArea extends React.Component {
|
2017-07-29 08:29:40 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2017-03-24 05:52:36 +08:00
|
|
|
this.state = {
|
|
|
|
paperWidth: 0,
|
|
|
|
paperHeight: 0,
|
|
|
|
showSlide: false,
|
|
|
|
};
|
2017-07-29 08:29:40 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
const { presentationPaper, whiteboardSizeAvailable } = this;
|
|
|
|
this.getInitialPaperSizes(presentationPaper, whiteboardSizeAvailable);
|
2017-03-24 05:52:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('resize', this.handleResize);
|
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// 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-04-28 06:18:53 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
getInitialPaperSizes(presentationPaper, whiteboardSizeAvailable) {
|
|
|
|
// determining the paperWidth and paperHeight (available space for the svg) on the initial load
|
|
|
|
let clientHeight;
|
|
|
|
let clientWidth;
|
|
|
|
if (this.props.userIsPresenter) {
|
|
|
|
clientHeight = whiteboardSizeAvailable.clientHeight;
|
|
|
|
clientWidth = whiteboardSizeAvailable.clientWidth;
|
|
|
|
} else {
|
|
|
|
clientHeight = presentationPaper.clientHeight;
|
|
|
|
clientWidth = presentationPaper.clientWidth;
|
|
|
|
}
|
2017-06-08 05:25:47 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// setting the state of the paperWidth and paperheight (available space for the svg)
|
|
|
|
// and set the showSlide to true to start rendering the slide
|
|
|
|
this.setState({
|
|
|
|
paperHeight: clientHeight,
|
|
|
|
paperWidth: clientWidth,
|
|
|
|
showSlide: true,
|
2017-03-24 05:52:36 +08:00
|
|
|
});
|
2017-07-29 08:29:40 +08:00
|
|
|
}
|
2017-04-28 06:18:53 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
handleResize() {
|
|
|
|
const { presentationPaper, whiteboardSizeAvailable } = this;
|
|
|
|
|
|
|
|
// if a user is a presenter - this means there is a whiteboardToolBar on the right
|
|
|
|
// and we have to get the width/height of the whiteboardSizeAvailable
|
|
|
|
// (inner hidden div with absolute position)
|
|
|
|
let clientHeight;
|
|
|
|
let clientWidth;
|
|
|
|
if (this.props.userIsPresenter) {
|
|
|
|
clientHeight = whiteboardSizeAvailable.clientHeight;
|
|
|
|
clientWidth = whiteboardSizeAvailable.clientWidth;
|
|
|
|
// user is not a presenter - we can get the sizes of the presentationPaper
|
|
|
|
// direct parent of the svg wrapper
|
2017-04-28 06:18:53 +08:00
|
|
|
} else {
|
2017-07-29 08:29:40 +08:00
|
|
|
clientHeight = presentationPaper.clientHeight;
|
|
|
|
clientWidth = presentationPaper.clientWidth;
|
2017-04-28 06:18:53 +08:00
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// updating the size of the space available for the slide
|
2017-03-24 05:52:36 +08:00
|
|
|
this.setState({
|
2017-04-28 06:18:53 +08:00
|
|
|
paperHeight: clientHeight,
|
|
|
|
paperWidth: clientWidth,
|
2017-03-24 05:52:36 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateSize() {
|
2017-07-29 08:29:40 +08:00
|
|
|
const originalWidth = this.props.currentSlide.slide.width;
|
|
|
|
const originalHeight = this.props.currentSlide.slide.height;
|
|
|
|
|
2017-03-24 05:52:36 +08:00
|
|
|
let adjustedWidth;
|
|
|
|
let adjustedHeight;
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// Slide has a portrait orientation
|
2017-03-24 05:52:36 +08:00
|
|
|
if (originalWidth <= originalHeight) {
|
2017-07-29 08:29:40 +08:00
|
|
|
adjustedWidth = (this.state.paperHeight * originalWidth) / originalHeight;
|
|
|
|
if (this.state.paperWidth < adjustedWidth) {
|
|
|
|
adjustedHeight = (this.state.paperHeight * this.state.paperWidth) / adjustedWidth;
|
2017-03-24 05:52:36 +08:00
|
|
|
adjustedWidth = this.state.paperWidth;
|
|
|
|
} else {
|
|
|
|
adjustedHeight = this.state.paperHeight;
|
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// Slide has a landscape orientation
|
2017-03-24 05:52:36 +08:00
|
|
|
} else {
|
2017-07-29 08:29:40 +08:00
|
|
|
adjustedHeight = (this.state.paperWidth * originalHeight) / originalWidth;
|
2017-03-24 05:52:36 +08:00
|
|
|
if (this.state.paperHeight < adjustedHeight) {
|
2017-07-29 08:29:40 +08:00
|
|
|
adjustedWidth = (this.state.paperWidth * this.state.paperHeight) / adjustedHeight;
|
2017-03-24 05:52:36 +08:00
|
|
|
adjustedHeight = this.state.paperHeight;
|
|
|
|
} else {
|
|
|
|
adjustedWidth = this.state.paperWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
width: adjustedWidth,
|
|
|
|
height: adjustedHeight,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// renders the whole presentation area
|
2017-02-17 05:11:46 +08:00
|
|
|
renderPresentationArea() {
|
2017-07-29 08:29:40 +08:00
|
|
|
// sometimes tomcat publishes the slide url, but the actual file is not accessible (why?)
|
|
|
|
if (this.props.currentSlide &&
|
|
|
|
this.props.currentSlide.slide.width &&
|
|
|
|
this.props.currentSlide.slide.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
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// a reference to the slide object
|
|
|
|
const slideObj = this.props.currentSlide.slide;
|
2017-04-28 06:18:53 +08:00
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// calculating the svg's coordinate system; we set it based on the slide's width/height ratio
|
|
|
|
// the longest value becomes '1000' and the second is calculated accordingly to keep the ratio
|
|
|
|
// if we don't do it, then the shapes' thickness changes with the slides' resolution
|
|
|
|
// 1000 makes html5 shapes' thickness approximately match
|
|
|
|
// Flash client's shapes' thickness in a default view (full screen window) at this point.
|
2017-05-05 04:20:30 +08:00
|
|
|
let svgWidth;
|
|
|
|
let svgHeight;
|
2017-07-29 08:29:40 +08:00
|
|
|
if (slideObj.width > slideObj.height) {
|
2017-05-05 04:20:30 +08:00
|
|
|
svgWidth = 1000;
|
|
|
|
svgHeight = 1000 / (slideObj.width / slideObj.height);
|
|
|
|
} else {
|
|
|
|
svgHeight = 1000;
|
|
|
|
svgWidth = 1000 / (slideObj.height / slideObj.width);
|
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
// calculating viewBox and offsets for the current presentation
|
|
|
|
const x = ((-slideObj.x_offset * 2) * svgWidth) / 100;
|
|
|
|
const y = ((-slideObj.y_offset * 2) * svgHeight) / 100;
|
|
|
|
const viewBoxWidth = (svgWidth * slideObj.width_ratio) / 100;
|
|
|
|
const viewBoxHeight = (svgHeight * slideObj.height_ratio) / 100;
|
2017-04-28 06:18:53 +08:00
|
|
|
|
2016-06-02 07:37:51 +08:00
|
|
|
return (
|
2017-03-24 05:52:36 +08:00
|
|
|
<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
|
|
|
}}
|
2016-06-02 07:37:51 +08:00
|
|
|
>
|
2017-06-08 04:29:35 +08:00
|
|
|
<CSSTransitionGroup
|
|
|
|
transitionName={{
|
|
|
|
enter: styles.enter,
|
|
|
|
enterActive: styles.enterActive,
|
|
|
|
appear: styles.appear,
|
|
|
|
appearActive: styles.appearActive,
|
|
|
|
}}
|
2017-07-29 08:29:40 +08:00
|
|
|
transitionAppear
|
|
|
|
transitionEnter
|
2017-06-08 04:29:35 +08:00
|
|
|
transitionLeave={false}
|
|
|
|
transitionAppearTimeout={400}
|
|
|
|
transitionEnterTimeout={400}
|
|
|
|
transitionLeaveTimeout={400}
|
2016-05-31 06:07:02 +08:00
|
|
|
>
|
2017-06-08 04:29:35 +08:00
|
|
|
<svg
|
|
|
|
width={svgWidth}
|
|
|
|
height={svgHeight}
|
2017-07-29 08:29:40 +08:00
|
|
|
ref={(ref) => { if (ref != null) { this.svggroup = ref; } }}
|
2017-06-08 04:29:35 +08:00
|
|
|
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"
|
|
|
|
slideHref={this.props.currentSlide.slide.img_uri}
|
|
|
|
svgWidth={svgWidth}
|
|
|
|
svgHeight={svgHeight}
|
|
|
|
/>
|
|
|
|
<ShapeGroupContainer
|
|
|
|
width={svgWidth}
|
|
|
|
height={svgHeight}
|
2017-07-29 08:29:40 +08:00
|
|
|
whiteboardId={slideObj.id}
|
2017-06-08 04:29:35 +08:00
|
|
|
/>
|
2017-08-15 08:15:11 +08:00
|
|
|
<CursorWrapperContainer
|
2017-06-03 03:25:02 +08:00
|
|
|
widthRatio={slideObj.width_ratio}
|
2017-06-08 04:29:35 +08:00
|
|
|
physicalWidthRatio={adjustedSizes.width / svgWidth}
|
2017-07-29 08:29:40 +08:00
|
|
|
slideWidth={svgWidth}
|
|
|
|
slideHeight={svgHeight}
|
2016-08-21 10:59:32 +08:00
|
|
|
/>
|
2017-06-08 04:29:35 +08:00
|
|
|
</g>
|
2017-08-09 04:55:38 +08:00
|
|
|
{this.props.userIsPresenter || this.props.multiUser ?
|
2017-06-08 04:29:35 +08:00
|
|
|
<PresentationOverlayContainer
|
|
|
|
slideWidth={svgWidth}
|
|
|
|
slideHeight={svgHeight}
|
|
|
|
>
|
|
|
|
<WhiteboardOverlayContainer
|
2017-07-29 08:29:40 +08:00
|
|
|
getSvgRef={this.getSvgRef}
|
|
|
|
whiteboardId={slideObj.id}
|
2017-06-08 04:29:35 +08:00
|
|
|
slideWidth={svgWidth}
|
|
|
|
slideHeight={svgHeight}
|
|
|
|
viewBoxX={x}
|
|
|
|
viewBoxY={y}
|
|
|
|
viewBoxWidth={viewBoxWidth}
|
|
|
|
viewBoxHeight={viewBoxHeight}
|
|
|
|
/>
|
|
|
|
</PresentationOverlayContainer>
|
2016-08-21 10:59:32 +08:00
|
|
|
: null }
|
2017-06-08 04:29:35 +08:00
|
|
|
</svg>
|
|
|
|
</CSSTransitionGroup>
|
2017-03-24 05:52:36 +08:00
|
|
|
</div>
|
2016-06-02 07:37:51 +08:00
|
|
|
);
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
return null;
|
2016-06-02 07:37:51 +08:00
|
|
|
}
|
|
|
|
|
2017-02-24 04:20:21 +08:00
|
|
|
renderPresentationToolbar() {
|
2016-08-06 02:39:24 +08:00
|
|
|
if (this.props.currentSlide) {
|
|
|
|
return (
|
2017-02-24 04:20:21 +08:00
|
|
|
<PresentationToolbarContainer
|
2016-08-06 02:39:24 +08:00
|
|
|
currentSlideNum={this.props.currentSlide.slide.num}
|
|
|
|
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() {
|
2017-07-29 08:29:40 +08:00
|
|
|
const adjustedSizes = this.calculateSize();
|
2017-04-19 08:54:51 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<WhiteboardToolbarContainer
|
2017-05-11 02:59:17 +08:00
|
|
|
whiteboardId={this.props.currentSlide.slide.id}
|
2017-04-19 08:54:51 +08:00
|
|
|
height={adjustedSizes.height}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-02 07:37:51 +08:00
|
|
|
render() {
|
|
|
|
return (
|
2017-02-17 05:11:46 +08:00
|
|
|
<div className={styles.presentationContainer}>
|
2017-07-29 08:29:40 +08:00
|
|
|
<div
|
|
|
|
ref={(ref) => { this.presentationPaper = ref; }}
|
|
|
|
className={styles.presentationPaper}
|
|
|
|
>
|
2017-03-24 05:52:36 +08:00
|
|
|
<div
|
2017-07-29 08:29:40 +08:00
|
|
|
ref={(ref) => { this.whiteboardSizeAvailable = ref; }}
|
|
|
|
className={styles.whiteboardSizeAvailable}
|
|
|
|
/>
|
|
|
|
{this.state.showSlide ?
|
2017-03-24 05:52:36 +08:00
|
|
|
this.renderPresentationArea()
|
|
|
|
: null }
|
2017-08-09 04:55:38 +08:00
|
|
|
{this.props.userIsPresenter || this.props.multiUser ?
|
2017-04-19 08:54:51 +08:00
|
|
|
this.renderWhiteboardToolbar()
|
|
|
|
: null }
|
2017-07-29 08:29:40 +08:00
|
|
|
</div>
|
2016-06-30 06:00:06 +08:00
|
|
|
<PollingContainer />
|
2017-02-24 04:20:21 +08:00
|
|
|
{this.renderPresentationToolbar()}
|
2016-05-31 06:07:02 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-29 08:29:40 +08:00
|
|
|
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,
|
|
|
|
slide: PropTypes.shape({
|
|
|
|
current: PropTypes.bool.isRequired,
|
|
|
|
height: PropTypes.number.isRequired,
|
|
|
|
width: PropTypes.number.isRequired,
|
|
|
|
height_ratio: PropTypes.number.isRequired,
|
|
|
|
width_ratio: PropTypes.number.isRequired,
|
|
|
|
x_offset: PropTypes.number.isRequired,
|
|
|
|
y_offset: PropTypes.number.isRequired,
|
|
|
|
num: PropTypes.number.isRequired,
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
img_uri: PropTypes.string.isRequired,
|
|
|
|
// TODO we don't use any of thefollowing uris here
|
|
|
|
swf_uri: PropTypes.string.isRequired,
|
|
|
|
thumb_uri: PropTypes.string.isRequired,
|
|
|
|
txt_uri: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
}),
|
2017-08-15 08:15:11 +08:00
|
|
|
|
|
|
|
// current multi-user status
|
|
|
|
multiUser: PropTypes.bool.isRequired,
|
2016-05-31 06:07:02 +08:00
|
|
|
};
|