bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/whiteboard/container.jsx

154 lines
4.7 KiB
React
Raw Normal View History

import { withTracker } from 'meteor/react-meteor-data';
import PropTypes from 'prop-types';
import React, { useContext } from 'react';
import {
ColorStyle,
DashStyle,
SizeStyle,
TDShapeType,
} from '@tldraw/tldraw';
import SettingsService from '/imports/ui/services/settings';
import {
getShapes,
getCurrentPres,
initDefaultPages,
persistShape,
removeShapes,
isMultiUserActive,
hasMultiUserAccess,
changeCurrentSlide,
notifyNotAllowedChange,
notifyShapeNumberExceeded,
toggleToolsAnimations,
} from './service';
import Whiteboard from './component';
import { UsersContext } from '../components-data/users-context/context';
import Auth from '/imports/ui/services/auth';
import PresentationToolbarService from '../presentation/presentation-toolbar/service';
import { layoutSelect } from '../layout/context';
2023-02-06 21:37:34 +08:00
import FullscreenService from '/imports/ui/components/common/fullscreen-button/service';
2023-03-27 23:45:16 +08:00
import deviceInfo from '/imports/utils/deviceInfo';
2022-04-05 22:49:13 +08:00
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
const WHITEBOARD_CONFIG = Meteor.settings.public.whiteboard;
2022-04-05 22:49:13 +08:00
const WhiteboardContainer = (props) => {
const usingUsersContext = useContext(UsersContext);
const isRTL = layoutSelect((i) => i.isRTL);
const width = layoutSelect((i) => i?.output?.presentation?.width);
const height = layoutSelect((i) => i?.output?.presentation?.height);
2023-04-13 02:36:13 +08:00
const sidebarNavigationWidth = layoutSelect((i) => i?.output?.sidebarNavigation?.width);
const { users } = usingUsersContext;
const currentUser = users[Auth.meetingID][Auth.userID];
const isPresenter = currentUser.presenter;
const isModerator = currentUser.role === ROLE_MODERATOR;
2023-02-03 20:49:49 +08:00
const { maxStickyNoteLength, maxNumberOfAnnotations } = WHITEBOARD_CONFIG;
const fontFamily = WHITEBOARD_CONFIG.styles.text.family;
2023-02-06 21:37:34 +08:00
const handleToggleFullScreen = (ref) => FullscreenService.toggleFullScreen(ref);
const { shapes } = props;
const hasShapeAccess = (id) => {
const owner = shapes[id]?.userId;
const isBackgroundShape = id?.includes('slide-background');
const hasAccess = !isBackgroundShape
&& ((owner && owner === currentUser?.userId) || !owner || isPresenter || isModerator);
return hasAccess;
};
// set shapes as locked for those who aren't allowed to edit it
Object.entries(shapes).forEach(([shapeId, shape]) => {
if (!shape.isLocked && !hasShapeAccess(shapeId)) {
const modShape = shape;
modShape.isLocked = true;
}
});
return (
<Whiteboard
{... {
isPresenter,
isModerator,
currentUser,
isRTL,
width,
height,
maxStickyNoteLength,
maxNumberOfAnnotations,
fontFamily,
hasShapeAccess,
2023-02-06 21:37:34 +08:00
handleToggleFullScreen,
2023-04-13 02:36:13 +08:00
sidebarNavigationWidth,
}}
{...props}
meetingId={Auth.meetingID}
/>
);
2022-04-05 22:49:13 +08:00
};
export default withTracker(({
whiteboardId,
curPageId,
intl,
slidePosition,
svgUri,
2023-02-06 21:37:34 +08:00
podId,
presentationId,
darkTheme,
}) => {
2023-02-03 20:49:49 +08:00
const shapes = getShapes(whiteboardId, curPageId, intl);
const curPres = getCurrentPres();
2023-03-27 23:45:16 +08:00
const { isIphone } = deviceInfo;
shapes['slide-background-shape'] = {
assetId: `slide-background-asset-${curPageId}`,
childIndex: -1,
id: 'slide-background-shape',
name: 'Image',
type: TDShapeType.Image,
parentId: `${curPageId}`,
point: [0, 0],
isLocked: true,
size: [slidePosition?.width || 0, slidePosition?.height || 0],
style: {
dash: DashStyle.Draw,
size: SizeStyle.Medium,
color: ColorStyle.Blue,
},
};
const assets = {};
assets[`slide-background-asset-${curPageId}`] = {
id: `slide-background-asset-${curPageId}`,
size: [slidePosition?.width || 0, slidePosition?.height || 0],
src: svgUri,
type: 'image',
};
2022-04-05 22:49:13 +08:00
return {
initDefaultPages,
persistShape,
isMultiUserActive,
hasMultiUserAccess,
changeCurrentSlide,
shapes,
assets,
curPres,
removeShapes,
2022-05-12 05:58:16 +08:00
zoomSlide: PresentationToolbarService.zoomSlide,
2022-05-19 08:52:45 +08:00
skipToSlide: PresentationToolbarService.skipToSlide,
2023-02-06 21:37:34 +08:00
nextSlide: PresentationToolbarService.nextSlide,
previousSlide: PresentationToolbarService.previousSlide,
numberOfSlides: PresentationToolbarService.getNumberOfSlides(podId, presentationId),
notifyNotAllowedChange,
notifyShapeNumberExceeded,
darkTheme,
whiteboardToolbarAutoHide: SettingsService?.application?.whiteboardToolbarAutoHide,
animations: SettingsService?.application?.animations,
toggleToolsAnimations,
2023-03-27 23:45:16 +08:00
isIphone,
2022-04-05 22:49:13 +08:00
};
})(WhiteboardContainer);
WhiteboardContainer.propTypes = {
shapes: PropTypes.objectOf(PropTypes.shape).isRequired,
};