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

962 lines
29 KiB
React
Raw Normal View History

2023-08-01 22:01:27 +08:00
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import WhiteboardContainer from '/imports/ui/components/whiteboard/container';
import { HUNDRED_PERCENT, MAX_PERCENT } from '/imports/utils/slideCalcUtils';
import { SPACE } from '/imports/utils/keyCodes';
import { defineMessages, injectIntl } from 'react-intl';
import { toast } from 'react-toastify';
import { Session } from 'meteor/session';
import PresentationToolbarContainer from './presentation-toolbar/container';
import PresentationMenu from './presentation-menu/container';
import Styled from './styles';
import FullscreenService from '/imports/ui/components/common/fullscreen-button/service';
import Icon from '/imports/ui/components/common/icon/component';
import PollingContainer from '/imports/ui/components/polling/container';
import { ACTIONS, LAYOUT_TYPE } from '../layout/enums';
import DEFAULT_VALUES from '../layout/defaultValues';
import { colorContentBackground } from '/imports/ui/stylesheets/styled-components/palette';
import browserInfo from '/imports/utils/browserInfo';
import { addNewAlert } from '../screenreader-alert/service';
import { clearCursors } from '/imports/ui/components/whiteboard/cursors/service';
2023-08-01 22:08:27 +08:00
import { debounce } from 'radash';
2019-03-12 00:21:12 +08:00
const intlMessages = defineMessages({
presentationLabel: {
2023-08-01 22:01:27 +08:00
id: 'app.presentationUploder.title',
description: 'presentation area element label',
2019-03-12 00:21:12 +08:00
},
2019-05-10 01:57:06 +08:00
changeNotification: {
2023-08-01 22:01:27 +08:00
id: 'app.presentation.notificationLabel',
description: 'label displayed in toast when presentation switches',
2019-05-10 01:57:06 +08:00
},
downloadLabel: {
2023-08-01 22:01:27 +08:00
id: 'app.presentation.downloadLabel',
description: 'label for downloadable presentations',
},
2020-08-20 09:48:10 +08:00
slideContentStart: {
2023-08-01 22:01:27 +08:00
id: 'app.presentation.startSlideContent',
description: 'Indicate the slide content start',
2020-08-20 09:48:10 +08:00
},
slideContentEnd: {
2023-08-01 22:01:27 +08:00
id: 'app.presentation.endSlideContent',
description: 'Indicate the slide content end',
2020-08-20 09:48:10 +08:00
},
slideContentChanged: {
2023-08-01 22:01:27 +08:00
id: 'app.presentation.changedSlideContent',
description: 'Indicate the slide content has changed',
},
2020-08-20 09:48:10 +08:00
noSlideContent: {
2023-08-01 22:01:27 +08:00
id: 'app.presentation.emptySlideContent',
description: 'No content available for slide',
},
2019-03-12 00:21:12 +08:00
});
const { isSafari } = browserInfo;
const FULLSCREEN_CHANGE_EVENT = isSafari
2023-08-01 22:01:27 +08:00
? 'webkitfullscreenchange'
: 'fullscreenchange';
const getToolbarHeight = () => {
let height = 0;
2023-08-01 22:01:27 +08:00
const toolbarEl = document.getElementById('presentationToolbarWrapper');
if (toolbarEl) {
const { clientHeight } = toolbarEl;
height = clientHeight;
}
return height;
};
2021-06-09 21:49:59 +08:00
class Presentation extends PureComponent {
constructor() {
super();
this.state = {
2021-06-09 21:49:59 +08:00
presentationWidth: 0,
presentationHeight: 0,
zoom: 100,
2019-07-27 00:48:51 +08:00
isFullscreen: false,
2022-05-16 10:35:17 +08:00
tldrawAPI: null,
2022-08-15 06:49:39 +08:00
isPanning: false,
tldrawIsMounting: true,
isToolbarVisible: true,
hadPresentation: false,
};
this.currentPresentationToastId = null;
this.getSvgRef = this.getSvgRef.bind(this);
2023-06-13 03:11:52 +08:00
this.zoomChanger = debounce({ delay: 200 }, this.zoomChanger.bind(this));
this.updateLocalPosition = this.updateLocalPosition.bind(this);
this.panAndZoomChanger = this.panAndZoomChanger.bind(this);
2018-09-25 20:47:49 +08:00
this.fitToWidthHandler = this.fitToWidthHandler.bind(this);
2019-07-27 00:48:51 +08:00
this.onFullscreenChange = this.onFullscreenChange.bind(this);
2023-08-01 22:08:27 +08:00
this.getPresentationSizesAvailable =
this.getPresentationSizesAvailable.bind(this);
2023-06-13 03:11:52 +08:00
this.handleResize = debounce({ delay: 200 }, this.handleResize.bind(this));
2022-05-16 10:35:17 +08:00
this.setTldrawAPI = this.setTldrawAPI.bind(this);
this.setIsPanning = this.setIsPanning.bind(this);
this.setIsToolbarVisible = this.setIsToolbarVisible.bind(this);
this.handlePanShortcut = this.handlePanShortcut.bind(this);
this.renderPresentationMenu = this.renderPresentationMenu.bind(this);
2019-07-30 23:03:29 +08:00
this.onResize = () => setTimeout(this.handleResize.bind(this), 0);
2023-08-01 22:08:27 +08:00
this.renderCurrentPresentationToast =
this.renderCurrentPresentationToast.bind(this);
this.setPresentationRef = this.setPresentationRef.bind(this);
this.setTldrawIsMounting = this.setTldrawIsMounting.bind(this);
2023-08-01 22:01:27 +08:00
Session.set('componentPresentationWillUnmount', false);
}
static getDerivedStateFromProps(props, state) {
const { prevProps } = state;
const stateChange = { prevProps: props };
if (
2023-08-01 22:08:27 +08:00
props.userIsPresenter &&
(!prevProps || !prevProps.userIsPresenter) &&
props.currentSlide &&
props.slidePosition
) {
2023-08-01 22:08:27 +08:00
let potentialZoom =
100 / (props.slidePosition.viewBoxWidth / props.slidePosition.width);
potentialZoom = Math.max(
HUNDRED_PERCENT,
2023-08-01 22:08:27 +08:00
Math.min(MAX_PERCENT, potentialZoom)
);
stateChange.zoom = potentialZoom;
}
if (!prevProps) return stateChange;
// When presenter is changed or slide changed we reset localPosition
if (
2023-08-01 22:08:27 +08:00
prevProps.currentSlide?.id !== props.currentSlide?.id ||
prevProps.userIsPresenter !== props.userIsPresenter
) {
stateChange.localPosition = undefined;
2019-03-20 03:50:08 +08:00
}
return stateChange;
2019-03-20 03:50:08 +08:00
}
componentDidMount() {
this.getInitialPresentationSizes();
this.refPresentationContainer.addEventListener(
2023-08-01 22:01:27 +08:00
'keydown',
2023-08-01 22:08:27 +08:00
this.handlePanShortcut
);
this.refPresentationContainer.addEventListener(
2023-08-01 22:01:27 +08:00
'keyup',
2023-08-01 22:08:27 +08:00
this.handlePanShortcut
);
this.refPresentationContainer.addEventListener(
FULLSCREEN_CHANGE_EVENT,
2023-08-01 22:08:27 +08:00
this.onFullscreenChange
);
2023-08-01 22:01:27 +08:00
window.addEventListener('resize', this.onResize, false);
2021-05-18 04:25:07 +08:00
const {
currentSlide,
slidePosition,
numPages,
layoutContextDispatch,
currentPresentationId,
2021-05-18 04:25:07 +08:00
} = this.props;
2020-09-02 21:30:44 +08:00
if (currentPresentationId) {
this.setState({
hadPresentation: true,
});
}
if (currentSlide) {
layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_NUM_CURRENT_SLIDE,
value: currentSlide.num,
});
layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_CURRENT_SLIDE_SIZE,
value: {
width: slidePosition.width,
height: slidePosition.height,
},
});
layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_SLIDES_LENGTH,
value: numPages,
2023-04-13 21:56:54 +08:00
});
}
}
componentDidUpdate(prevProps) {
const {
currentPresentation,
slidePosition,
presentationIsOpen,
currentSlide,
publishedPoll,
setPresentationIsOpen,
restoreOnUpdate,
2020-04-23 22:07:44 +08:00
layoutContextDispatch,
userIsPresenter,
presentationBounds,
numCameras,
intl,
multiUser,
numPages,
2023-04-13 21:56:54 +08:00
currentPresentationId,
fitToWidth,
} = this.props;
const {
presentationWidth,
presentationHeight,
zoom,
isPanning,
presentationId,
hadPresentation,
} = this.state;
const {
numCameras: prevNumCameras,
presentationBounds: prevPresentationBounds,
multiUser: prevMultiUser,
} = prevProps;
2020-06-09 11:09:46 +08:00
if (prevMultiUser && !multiUser) {
clearCursors();
}
if (numCameras !== prevNumCameras) {
2020-06-09 11:09:46 +08:00
this.onResize();
}
if (numPages !== prevProps.numPages) {
layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_SLIDES_LENGTH,
value: numPages,
2023-04-13 21:56:54 +08:00
});
}
2022-01-25 01:52:24 +08:00
if (
2023-08-01 22:08:27 +08:00
currentSlide?.num != null &&
prevProps?.currentSlide?.num != null &&
currentSlide?.num !== prevProps.currentSlide?.num
2022-01-25 01:52:24 +08:00
) {
addNewAlert(
intl.formatMessage(intlMessages.slideContentChanged, {
0: currentSlide.num,
2023-08-01 22:08:27 +08:00
})
);
}
2022-03-11 22:57:43 +08:00
if (currentPresentation) {
2023-08-01 22:08:27 +08:00
const downloadableOn =
!prevProps?.currentPresentation?.downloadable &&
currentPresentation.downloadable;
2021-05-18 04:25:07 +08:00
const shouldCloseToast = !(
currentPresentation.downloadable && !userIsPresenter
);
2021-05-18 04:25:07 +08:00
if (
2023-08-01 22:08:27 +08:00
prevProps?.currentPresentation?.id !== currentPresentation.id ||
(downloadableOn && !userIsPresenter)
2021-05-18 04:25:07 +08:00
) {
if (this.currentPresentationToastId) {
toast.update(this.currentPresentationToastId, {
autoClose: shouldCloseToast,
render: this.renderCurrentPresentationToast(),
});
} else {
this.currentPresentationToastId = toast(
this.renderCurrentPresentationToast(),
{
onClose: () => {
this.currentPresentationToastId = null;
},
autoClose: shouldCloseToast,
2023-08-01 22:01:27 +08:00
className: 'actionToast currentPresentationToast',
2023-08-01 22:08:27 +08:00
}
);
2021-05-18 04:25:07 +08:00
}
}
2023-08-01 22:08:27 +08:00
const downloadableOff =
prevProps?.currentPresentation?.downloadable &&
!currentPresentation.downloadable;
2021-05-18 04:25:07 +08:00
if (this.currentPresentationToastId && downloadableOff) {
toast.update(this.currentPresentationToastId, {
2021-05-18 04:25:07 +08:00
autoClose: true,
render: this.renderCurrentPresentationToast(),
});
}
2022-03-11 22:57:43 +08:00
}
if (prevProps?.slidePosition && slidePosition) {
const { width: prevWidth, height: prevHeight } = prevProps.slidePosition;
const { width: currWidth, height: currHeight } = slidePosition;
if (prevWidth !== currWidth || prevHeight !== currHeight) {
layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_CURRENT_SLIDE_SIZE,
value: {
width: currWidth,
height: currHeight,
},
});
}
const presentationChanged = presentationId !== currentPresentationId;
2023-08-01 22:08:27 +08:00
const isInitialPresentation = currentPresentation.isInitialPresentation;
if (
2023-08-01 22:08:27 +08:00
!presentationIsOpen &&
restoreOnUpdate &&
(currentSlide || presentationChanged)
) {
2021-05-18 04:25:07 +08:00
const slideChanged = currentSlide.id !== prevProps.currentSlide.id;
2023-08-01 22:08:27 +08:00
const positionChanged =
slidePosition.viewBoxHeight !==
prevProps.slidePosition.viewBoxHeight ||
slidePosition.viewBoxWidth !== prevProps.slidePosition.viewBoxWidth;
2021-05-18 04:25:07 +08:00
const pollPublished = publishedPoll && !prevProps.publishedPoll;
if (
2023-08-01 22:08:27 +08:00
slideChanged ||
positionChanged ||
pollPublished ||
(presentationChanged && (hadPresentation || !isInitialPresentation))
) {
setPresentationIsOpen(layoutContextDispatch, !presentationIsOpen);
2021-05-18 04:25:07 +08:00
}
}
2021-05-18 04:25:07 +08:00
if (presentationChanged) {
this.setState({
presentationId: currentPresentationId,
hadPresentation: true,
});
}
if (
2023-08-01 22:08:27 +08:00
presentationBounds !== prevPresentationBounds ||
(!presentationWidth && !presentationHeight)
)
this.onResize();
2022-04-06 21:44:09 +08:00
} else if (slidePosition) {
const { width: currWidth, height: currHeight } = slidePosition;
layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_CURRENT_SLIDE_SIZE,
value: {
width: currWidth,
height: currHeight,
},
});
layoutContextDispatch({
type: ACTIONS.SET_PRESENTATION_NUM_CURRENT_SLIDE,
value: currentSlide.num,
});
}
if (
2023-08-01 22:08:27 +08:00
(zoom <= HUNDRED_PERCENT && isPanning && !fitToWidth) ||
(!userIsPresenter && prevProps.userIsPresenter)
) {
this.setIsPanning();
}
2019-03-20 03:50:08 +08:00
}
componentWillUnmount() {
2023-08-01 22:01:27 +08:00
Session.set('componentPresentationWillUnmount', true);
const { fullscreenContext, layoutContextDispatch } = this.props;
2023-08-01 22:01:27 +08:00
window.removeEventListener('resize', this.onResize, false);
this.refPresentationContainer.removeEventListener(
FULLSCREEN_CHANGE_EVENT,
2023-08-01 22:08:27 +08:00
this.onFullscreenChange
);
this.refPresentationContainer.removeEventListener(
2023-08-01 22:01:27 +08:00
'keydown',
2023-08-01 22:08:27 +08:00
this.handlePanShortcut
);
this.refPresentationContainer.removeEventListener(
2023-08-01 22:01:27 +08:00
'keyup',
2023-08-01 22:08:27 +08:00
this.handlePanShortcut
);
if (fullscreenContext) {
layoutContextDispatch({
type: ACTIONS.SET_FULLSCREEN_ELEMENT,
value: {
2023-08-01 22:01:27 +08:00
element: '',
group: '',
},
});
}
}
handlePanShortcut(e) {
const { userIsPresenter } = this.props;
const { isPanning } = this.state;
if (e.keyCode === SPACE && userIsPresenter) {
switch (e.type) {
2023-08-01 22:01:27 +08:00
case 'keyup':
return isPanning && this.setIsPanning();
2023-08-01 22:01:27 +08:00
case 'keydown':
return !isPanning && this.setIsPanning();
default:
}
}
return null;
2022-05-16 10:35:17 +08:00
}
2021-05-18 04:25:07 +08:00
handleResize() {
const presentationSizes = this.getPresentationSizesAvailable();
if (Object.keys(presentationSizes).length > 0) {
// updating the size of the space available for the slide
2023-08-01 22:01:27 +08:00
if (!Session.get('componentPresentationWillUnmount')) {
this.setState({
presentationHeight: presentationSizes.presentationHeight,
presentationWidth: presentationSizes.presentationWidth,
});
}
2021-05-18 04:25:07 +08:00
}
}
2019-07-27 00:48:51 +08:00
onFullscreenChange() {
const { isFullscreen } = this.state;
const newIsFullscreen = FullscreenService.isFullScreen(
2023-08-01 22:08:27 +08:00
this.refPresentationContainer
);
2019-07-27 00:48:51 +08:00
if (isFullscreen !== newIsFullscreen) {
this.setState({ isFullscreen: newIsFullscreen });
}
}
setTldrawAPI(api) {
this.setState({
tldrawAPI: api,
});
}
setTldrawIsMounting(value) {
this.setState({ tldrawIsMounting: value });
}
setIsPanning() {
this.setState((prevState) => ({
isPanning: !prevState.isPanning,
}));
}
setIsToolbarVisible(isVisible) {
this.setState({
isToolbarVisible: isVisible,
});
}
setPresentationRef(ref) {
this.refPresentationContainer = ref;
}
// 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 {
presentationBounds,
2021-06-09 21:49:59 +08:00
presentationAreaSize: newPresentationAreaSize,
} = this.props;
const presentationSizes = {
2021-06-09 21:49:59 +08:00
presentationWidth: 0,
presentationHeight: 0,
};
2021-08-05 12:22:07 +08:00
if (newPresentationAreaSize) {
2023-08-01 22:08:27 +08:00
presentationSizes.presentationWidth =
newPresentationAreaSize.presentationAreaWidth;
presentationSizes.presentationHeight =
newPresentationAreaSize.presentationAreaHeight -
(getToolbarHeight() || 0);
2021-06-09 21:49:59 +08:00
return presentationSizes;
}
2021-06-09 21:49:59 +08:00
presentationSizes.presentationWidth = presentationBounds.width;
presentationSizes.presentationHeight = presentationBounds.height;
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() {
2021-06-09 21:49:59 +08:00
// determining the presentationWidth and presentationHeight (available
// space for the svg) on the initial load
2018-10-19 01:03:11 +08:00
2017-09-18 09:58:37 +08:00
const presentationSizes = this.getPresentationSizesAvailable();
if (Object.keys(presentationSizes).length > 0) {
// setting the state of the available space for the svg
this.setState({
2021-06-09 21:49:59 +08:00
presentationHeight: presentationSizes.presentationHeight,
presentationWidth: presentationSizes.presentationWidth,
});
2017-09-06 09:36:15 +08:00
}
}
zoomChanger(zoom) {
this.setState({ zoom });
}
fitToWidthHandler() {
const { setPresentationFitToWidth, fitToWidth } = this.props;
setPresentationFitToWidth(!fitToWidth)
this.setState({
zoom: HUNDRED_PERCENT,
});
}
updateLocalPosition(x, y, width, height, zoom) {
this.setState({
localPosition: {
x,
y,
width,
height,
},
zoom,
});
}
calculateSize(viewBoxDimensions) {
const { presentationHeight, presentationWidth } = this.state;
const { userIsPresenter, currentSlide, slidePosition, fitToWidth } = this.props;
if (!currentSlide || !slidePosition) {
return { width: 0, height: 0 };
}
const originalWidth = slidePosition.width;
const originalHeight = slidePosition.height;
const viewBoxWidth = viewBoxDimensions.width;
const viewBoxHeight = viewBoxDimensions.height;
let svgWidth;
let svgHeight;
if (!userIsPresenter) {
2021-06-09 21:49:59 +08:00
svgWidth = (presentationHeight * viewBoxWidth) / viewBoxHeight;
if (presentationWidth < svgWidth) {
svgHeight = (presentationHeight * presentationWidth) / svgWidth;
svgWidth = presentationWidth;
} else {
2021-06-09 21:49:59 +08:00
svgHeight = presentationHeight;
}
} else if (!fitToWidth) {
2021-06-09 21:49:59 +08:00
svgWidth = (presentationHeight * originalWidth) / originalHeight;
if (presentationWidth < svgWidth) {
svgHeight = (presentationHeight * presentationWidth) / svgWidth;
svgWidth = presentationWidth;
} else {
2021-06-09 21:49:59 +08:00
svgHeight = presentationHeight;
}
2019-03-20 03:50:08 +08:00
} else {
2021-06-09 21:49:59 +08:00
svgWidth = presentationWidth;
svgHeight = (svgWidth * originalHeight) / originalWidth;
2021-06-09 21:49:59 +08:00
if (svgHeight > presentationHeight) svgHeight = presentationHeight;
}
2023-08-01 22:01:27 +08:00
if (typeof svgHeight !== 'number' || typeof svgWidth !== 'number') {
2021-03-04 02:59:34 +08:00
return { width: 0, height: 0 };
}
return {
width: svgWidth,
height: svgHeight,
};
}
panAndZoomChanger(w, h, x, y) {
const { currentSlide, podId, zoomSlide } = this.props;
zoomSlide(currentSlide.num, podId, w, h, x, y);
}
2022-05-16 10:35:17 +08:00
renderPresentationToolbar(svgWidth = 0) {
const {
2019-02-12 21:35:52 +08:00
currentSlide,
podId,
isMobile,
layoutType,
numCameras,
fullscreenElementId,
fullscreenContext,
layoutContextDispatch,
presentationIsOpen,
slidePosition,
addWhiteboardGlobalAccess,
removeWhiteboardGlobalAccess,
multiUserSize,
multiUser,
fitToWidth,
2019-02-12 21:35:52 +08:00
} = this.props;
const { zoom, isPanning } = this.state;
if (!currentSlide) return null;
const { presentationToolbarMinWidth } = DEFAULT_VALUES;
2023-08-01 22:08:27 +08:00
const toolbarWidth =
(this.refWhiteboardArea && svgWidth > presentationToolbarMinWidth) ||
isMobile ||
(layoutType === LAYOUT_TYPE.VIDEO_FOCUS && numCameras > 0)
? svgWidth
: presentationToolbarMinWidth;
return (
<PresentationToolbarContainer
{...{
fitToWidth,
zoom,
podId,
currentSlide,
slidePosition,
toolbarWidth,
fullscreenElementId,
layoutContextDispatch,
presentationIsOpen,
}}
2022-08-15 06:49:39 +08:00
setIsPanning={this.setIsPanning}
isPanning={isPanning}
2019-02-08 01:47:28 +08:00
currentSlideNum={currentSlide.num}
presentationId={currentSlide.presentationId}
zoomChanger={this.zoomChanger}
2018-09-25 20:47:49 +08:00
fitToWidthHandler={this.fitToWidthHandler}
isFullscreen={fullscreenContext}
fullscreenAction={ACTIONS.SET_FULLSCREEN_ELEMENT}
fullscreenRef={this.refPresentationContainer}
addWhiteboardGlobalAccess={addWhiteboardGlobalAccess}
removeWhiteboardGlobalAccess={removeWhiteboardGlobalAccess}
multiUserSize={multiUserSize}
multiUser={multiUser}
whiteboardId={currentSlide?.id}
/>
);
2016-08-06 02:39:24 +08:00
}
renderCurrentPresentationToast() {
const {
intl,
currentPresentation,
userIsPresenter,
downloadPresentationUri,
} = this.props;
const { downloadable } = currentPresentation;
return (
2023-08-01 22:08:27 +08:00
<Styled.InnerToastWrapper data-test='currentPresentationToast'>
2021-11-09 01:28:22 +08:00
<Styled.ToastIcon>
<Styled.IconWrapper>
2023-08-01 22:08:27 +08:00
<Icon iconName='presentation' />
2021-11-09 01:28:22 +08:00
</Styled.IconWrapper>
</Styled.ToastIcon>
2023-08-01 22:08:27 +08:00
<Styled.ToastTextContent data-test='toastSmallMsg'>
<div>{`${intl.formatMessage(intlMessages.changeNotification)}`}</div>
2021-11-09 01:28:22 +08:00
<Styled.PresentationName>{`${currentPresentation.name}`}</Styled.PresentationName>
</Styled.ToastTextContent>
{downloadable && !userIsPresenter ? (
<Styled.ToastDownload>
<Styled.ToastSeparator />
<a
2023-08-01 22:08:27 +08:00
data-test='toastDownload'
aria-label={`${intl.formatMessage(intlMessages.downloadLabel)} ${
currentPresentation.name
}`}
href={downloadPresentationUri}
2023-08-01 22:08:27 +08:00
target='_blank'
rel='noopener noreferrer'
>
{intl.formatMessage(intlMessages.downloadLabel)}
</a>
</Styled.ToastDownload>
) : null}
2021-11-09 01:28:22 +08:00
</Styled.InnerToastWrapper>
);
}
renderPresentationMenu() {
const {
intl,
fullscreenElementId,
layoutContextDispatch,
} = this.props;
const { tldrawAPI, isToolbarVisible } = this.state;
return (
<PresentationMenu
fullscreenRef={this.refPresentationContainer}
tldrawAPI={tldrawAPI}
elementName={intl.formatMessage(intlMessages.presentationLabel)}
elementId={fullscreenElementId}
layoutContextDispatch={layoutContextDispatch}
setIsToolbarVisible={this.setIsToolbarVisible}
isToolbarVisible={isToolbarVisible}
/>
);
}
render() {
2019-03-12 00:21:12 +08:00
const {
userIsPresenter,
2022-05-07 00:37:43 +08:00
currentSlide,
slidePosition,
presentationBounds,
fullscreenContext,
isMobile,
layoutType,
numCameras,
currentPresentation,
2022-05-12 05:58:16 +08:00
podId,
intl,
2022-06-02 23:00:28 +08:00
isViewersCursorLocked,
fullscreenElementId,
layoutContextDispatch,
presentationIsOpen,
darkTheme,
fitToWidth,
2019-03-12 00:21:12 +08:00
} = this.props;
2019-03-12 21:56:05 +08:00
const {
isFullscreen,
localPosition,
zoom,
tldrawIsMounting,
isPanning,
2023-03-13 20:17:14 +08:00
tldrawAPI,
isToolbarVisible,
2019-03-12 21:56:05 +08:00
} = this.state;
2019-02-08 01:47:28 +08:00
let viewBoxDimensions;
if (userIsPresenter && localPosition) {
viewBoxDimensions = {
width: localPosition.width,
height: localPosition.height,
};
2019-08-02 01:50:39 +08:00
} else if (slidePosition) {
viewBoxDimensions = {
width: slidePosition.viewBoxWidth,
height: slidePosition.viewBoxHeight,
};
2019-08-02 01:50:39 +08:00
} else {
viewBoxDimensions = {
width: 0,
height: 0,
};
}
const svgDimensions = this.calculateSize(viewBoxDimensions);
const svgHeight = svgDimensions.height;
const svgWidth = svgDimensions.width;
2019-02-19 20:27:54 +08:00
const toolbarHeight = getToolbarHeight();
2019-02-19 20:27:54 +08:00
const { presentationToolbarMinWidth } = DEFAULT_VALUES;
2023-08-01 22:08:27 +08:00
const isLargePresentation =
(svgWidth > presentationToolbarMinWidth || isMobile) &&
!(
layoutType === LAYOUT_TYPE.VIDEO_FOCUS &&
numCameras > 0 &&
!fullscreenContext
);
const containerWidth = isLargePresentation
? svgWidth
: presentationToolbarMinWidth;
const slideContent = currentSlide?.content
? `${intl.formatMessage(intlMessages.slideContentStart)}
${currentSlide.content}
${intl.formatMessage(intlMessages.slideContentEnd)}`
: intl.formatMessage(intlMessages.noSlideContent);
2022-04-05 22:49:13 +08:00
return (
<>
2022-04-05 22:49:13 +08:00
<Styled.PresentationContainer
2023-08-01 22:08:27 +08:00
role='region'
data-test='presentationContainer'
ref={(ref) => {
this.refPresentationContainer = ref;
}}
2022-04-05 22:49:13 +08:00
style={{
top: presentationBounds.top,
left: presentationBounds.left,
right: presentationBounds.right,
width: presentationBounds.width,
height: presentationBounds.height,
2023-08-01 22:01:27 +08:00
display: !presentationIsOpen ? 'none' : 'flex',
overflow: 'hidden',
2022-04-05 22:49:13 +08:00
zIndex: fullscreenContext ? presentationBounds.zIndex : undefined,
background:
2023-08-01 22:08:27 +08:00
layoutType === LAYOUT_TYPE.VIDEO_FOCUS &&
numCameras > 0 &&
!fullscreenContext
? colorContentBackground
: null,
2022-04-05 22:49:13 +08:00
}}
>
<Styled.Presentation
ref={(ref) => {
this.refPresentation = ref;
}}
>
<Styled.SvgContainer
style={{
height: svgHeight + toolbarHeight,
}}
>
<div
style={{
2023-08-01 22:01:27 +08:00
position: 'absolute',
width: svgDimensions.width < 0 ? 0 : svgDimensions.width,
height: svgDimensions.height < 0 ? 0 : svgDimensions.height,
2023-08-01 22:01:27 +08:00
textAlign: 'center',
display: !presentationIsOpen ? 'none' : 'block',
}}
2023-08-01 22:08:27 +08:00
id='presentationInnerWrapper'
>
2023-08-01 22:08:27 +08:00
<Styled.VisuallyHidden id='currentSlideText'>
{slideContent}
</Styled.VisuallyHidden>
2023-08-01 22:08:27 +08:00
{!tldrawIsMounting &&
currentSlide &&
this.renderPresentationMenu()}
<WhiteboardContainer
whiteboardId={currentSlide?.id}
podId={podId}
slidePosition={slidePosition}
getSvgRef={this.getSvgRef}
2023-03-13 20:17:14 +08:00
tldrawAPI={tldrawAPI}
setTldrawAPI={this.setTldrawAPI}
2023-08-01 22:01:27 +08:00
curPageId={currentSlide?.num.toString() || '0'}
svgUri={currentSlide?.svgUri}
intl={intl}
presentationWidth={svgWidth}
presentationHeight={svgHeight}
2023-01-26 02:49:09 +08:00
presentationAreaHeight={presentationBounds?.height}
presentationAreaWidth={presentationBounds?.width}
isViewersCursorLocked={isViewersCursorLocked}
isPanning={isPanning}
zoomChanger={this.zoomChanger}
fitToWidth={fitToWidth}
zoomValue={zoom}
setTldrawIsMounting={this.setTldrawIsMounting}
setIsToolbarVisible={this.setIsToolbarVisible}
2023-02-06 21:37:34 +08:00
isFullscreen={isFullscreen}
fullscreenAction={ACTIONS.SET_FULLSCREEN_ELEMENT}
fullscreenElementId={fullscreenElementId}
layoutContextDispatch={layoutContextDispatch}
fullscreenRef={this.refPresentationContainer}
presentationId={currentPresentation?.id}
darkTheme={darkTheme}
isToolbarVisible={isToolbarVisible}
/>
{isFullscreen && <PollingContainer />}
</div>
{!tldrawIsMounting && (
<Styled.PresentationToolbar
ref={(ref) => {
this.refPresentationToolbar = ref;
}}
style={{
width: containerWidth,
}}
>
{this.renderPresentationToolbar(svgWidth)}
</Styled.PresentationToolbar>
)}
</Styled.SvgContainer>
</Styled.Presentation>
</Styled.PresentationContainer>
2022-06-02 23:00:28 +08:00
</>
);
}
}
export default injectIntl(Presentation);
2021-06-09 21:49:59 +08:00
Presentation.propTypes = {
podId: PropTypes.string.isRequired,
// Defines a boolean value to detect whether a current user is a presenter
userIsPresenter: PropTypes.bool.isRequired,
currentSlide: PropTypes.shape({
presentationId: PropTypes.string.isRequired,
current: PropTypes.bool.isRequired,
num: PropTypes.number.isRequired,
id: PropTypes.string.isRequired,
imageUri: PropTypes.string.isRequired,
curPageId: PropTypes.string,
svgUri: PropTypes.string.isRequired,
content: PropTypes.string.isRequired,
}),
slidePosition: PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
viewBoxWidth: PropTypes.number.isRequired,
viewBoxHeight: PropTypes.number.isRequired,
}),
2017-08-15 08:15:11 +08:00
// current multi-user status
multiUser: PropTypes.bool.isRequired,
setPresentationIsOpen: PropTypes.func.isRequired,
layoutContextDispatch: PropTypes.func.isRequired,
currentPresentation: PropTypes.shape({
downloadable: PropTypes.bool.isRequired,
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}),
presentationIsOpen: PropTypes.bool.isRequired,
numPages: PropTypes.number.isRequired,
publishedPoll: PropTypes.bool.isRequired,
presentationBounds: PropTypes.shape({
top: PropTypes.number,
left: PropTypes.number,
right: PropTypes.number,
width: PropTypes.number,
height: PropTypes.number,
zIndex: PropTypes.number,
}),
restoreOnUpdate: PropTypes.bool.isRequired,
numCameras: PropTypes.number.isRequired,
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
isMobile: PropTypes.bool.isRequired,
fullscreenContext: PropTypes.bool.isRequired,
presentationAreaSize: PropTypes.shape({
presentationAreaWidth: PropTypes.number.isRequired,
presentationAreaHeight: PropTypes.number.isRequired,
}),
zoomSlide: PropTypes.func.isRequired,
addWhiteboardGlobalAccess: PropTypes.func.isRequired,
removeWhiteboardGlobalAccess: PropTypes.func.isRequired,
multiUserSize: PropTypes.number.isRequired,
layoutType: PropTypes.string.isRequired,
fullscreenElementId: PropTypes.string.isRequired,
downloadPresentationUri: PropTypes.string,
isViewersCursorLocked: PropTypes.bool.isRequired,
darkTheme: PropTypes.bool.isRequired,
};
2021-06-09 21:49:59 +08:00
Presentation.defaultProps = {
currentSlide: undefined,
slidePosition: undefined,
currentPresentation: undefined,
presentationAreaSize: undefined,
presentationBounds: undefined,
downloadPresentationUri: undefined,
2022-05-07 00:37:43 +08:00
};