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

170 lines
5.3 KiB
React
Raw Normal View History

import { withTracker } from 'meteor/react-meteor-data';
import PropTypes from 'prop-types';
import React, { useContext } from 'react';
2023-08-01 22:08:27 +08:00
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';
2023-08-01 22:08:27 +08:00
import {
layoutSelect,
layoutDispatch,
} from '/imports/ui/components/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-08-01 22:08:27 +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;
const handleToggleFullScreen = (ref) =>
FullscreenService.toggleFullScreen(ref);
2023-08-01 22:08:27 +08:00
const layoutContextDispatch = layoutDispatch();
const { shapes } = props;
const hasShapeAccess = (id) => {
const owner = shapes[id]?.userId;
const isBackgroundShape = id?.includes('slide-background');
2023-05-10 02:51:35 +08:00
const isPollsResult = shapes[id]?.name?.includes('poll-result');
2023-08-01 22:08:27 +08:00
const hasAccess =
(!isBackgroundShape && !isPollsResult) ||
(isPresenter &&
((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) && !shape.name?.includes('poll-result')) {
const modShape = shape;
modShape.isLocked = true;
}
});
return (
<Whiteboard
2023-08-01 22:08:27 +08:00
{...{
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,
2023-08-01 22:08:27 +08:00
layoutContextDispatch,
}}
{...props}
meetingId={Auth.meetingID}
/>
);
2022-04-05 22:49:13 +08:00
};
2023-08-01 22:08:27 +08:00
export default withTracker(
({
whiteboardId,
curPageId,
intl,
slidePosition,
svgUri,
podId,
presentationId,
darkTheme,
isViewersAnnotationsLocked,
2023-08-01 22:08:27 +08:00
}) => {
const shapes = getShapes(whiteboardId, curPageId, intl, isViewersAnnotationsLocked);
2023-08-01 22:08:27 +08:00
const curPres = getCurrentPres();
const { isIphone } = deviceInfo;
2023-08-01 22:08:27 +08:00
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,
},
};
2023-08-01 22:08:27 +08:00
const assets = {};
assets[`slide-background-asset-${curPageId}`] = {
id: `slide-background-asset-${curPageId}`,
size: [slidePosition?.width || 0, slidePosition?.height || 0],
src: svgUri,
type: 'image',
};
2023-08-01 22:08:27 +08:00
return {
initDefaultPages,
persistShape,
isMultiUserActive,
hasMultiUserAccess,
changeCurrentSlide,
2023-08-01 22:08:27 +08:00
shapes,
assets,
curPres,
removeShapes,
2023-08-01 22:08:27 +08:00
zoomSlide: PresentationToolbarService.zoomSlide,
skipToSlide: PresentationToolbarService.skipToSlide,
nextSlide: PresentationToolbarService.nextSlide,
previousSlide: PresentationToolbarService.previousSlide,
numberOfSlides: PresentationToolbarService.getNumberOfSlides(
podId,
presentationId
),
notifyNotAllowedChange,
notifyShapeNumberExceeded,
2023-08-01 22:08:27 +08:00
darkTheme,
whiteboardToolbarAutoHide:
SettingsService?.application?.whiteboardToolbarAutoHide,
animations: SettingsService?.application?.animations,
toggleToolsAnimations,
2023-08-01 22:08:27 +08:00
isIphone,
};
}
)(WhiteboardContainer);
WhiteboardContainer.propTypes = {
shapes: PropTypes.objectOf(PropTypes.shape).isRequired,
};