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

272 lines
8.1 KiB
React
Raw Normal View History

import React, { useEffect, useState } from 'react';
import { useSubscription, useMutation } from '@apollo/client';
2023-09-28 04:42:47 +08:00
import {
CURRENT_PRESENTATION_PAGE_SUBSCRIPTION,
2023-09-28 10:15:33 +08:00
CURRENT_PAGE_ANNOTATIONS_STREAM,
2023-10-12 04:17:10 +08:00
CURRENT_PAGE_WRITERS_SUBSCRIPTION,
2023-09-28 04:42:47 +08:00
} from './queries';
import { CURSOR_SUBSCRIPTION } from './cursors/queries';
2023-09-28 04:42:47 +08:00
import {
initDefaultPages,
persistShape,
notifyNotAllowedChange,
notifyShapeNumberExceeded,
toggleToolsAnimations,
formatAnnotations,
} from './service';
import CursorService from './cursors/service';
2023-09-28 04:42:47 +08:00
import SettingsService from '/imports/ui/services/settings';
import Auth from '/imports/ui/services/auth';
import {
layoutSelect,
layoutDispatch,
} from '/imports/ui/components/layout/context';
import FullscreenService from '/imports/ui/components/common/fullscreen-button/service';
import deviceInfo from '/imports/utils/deviceInfo';
import Whiteboard from './component';
2023-10-28 00:05:43 +08:00
import POLL_RESULTS_SUBSCRIPTION from '/imports/ui/core/graphql/queries/pollResultsSubscription';
2023-11-23 04:01:18 +08:00
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import useMeeting from '/imports/ui/core/hooks/useMeeting';
import {
AssetRecordType,
} from "@tldraw/tldraw";
2024-01-24 19:37:51 +08:00
import {
PRESENTATION_SET_ZOOM,
PRES_ANNOTATION_DELETE,
PRES_ANNOTATION_SUBMIT,
} from '../presentation/mutations';
2023-09-28 04:42:47 +08:00
const WHITEBOARD_CONFIG = Meteor.settings.public.whiteboard;
const WhiteboardContainer = (props) => {
const {
intl,
slidePosition,
svgUri,
zoomChanger,
2023-09-28 04:42:47 +08:00
} = props;
const [annotations, setAnnotations] = useState([]);
2024-02-21 10:18:36 +08:00
const [shapes, setShapes] = useState({});
const meeting = useMeeting((m) => ({
lockSettings: m?.lockSettings,
}));
2023-09-28 04:42:47 +08:00
const { data: presentationPageData } = useSubscription(CURRENT_PRESENTATION_PAGE_SUBSCRIPTION);
const { pres_page_curr: presentationPageArray } = (presentationPageData || {});
const currentPresentationPage = presentationPageArray && presentationPageArray[0];
const curPageId = currentPresentationPage?.num;
const presentationId = currentPresentationPage?.presentationId;
const { data: whiteboardWritersData } = useSubscription(CURRENT_PAGE_WRITERS_SUBSCRIPTION, {
variables: { pageId: currentPresentationPage?.pageId },
skip: !currentPresentationPage?.pageId,
});
2023-10-12 04:17:10 +08:00
const whiteboardWriters = whiteboardWritersData?.pres_page_writers || [];
const hasWBAccess = whiteboardWriters?.some((writer) => writer.userId === Auth.userID);
const [presentationSetZoom] = useMutation(PRESENTATION_SET_ZOOM);
2024-01-23 22:31:39 +08:00
const [presentationDeleteAnnotations] = useMutation(PRES_ANNOTATION_DELETE);
2024-01-24 19:37:51 +08:00
const [presentationSubmitAnnotations] = useMutation(PRES_ANNOTATION_SUBMIT);
2024-01-23 22:31:39 +08:00
const removeShapes = (shapeIds) => {
presentationDeleteAnnotations({
variables: {
pageId: currentPresentationPage?.pageId,
annotationsIds: shapeIds,
},
});
};
const zoomSlide = (widthRatio, heightRatio, xOffset, yOffset) => {
const { pageId, num } = currentPresentationPage;
presentationSetZoom({
variables: {
presentationId,
pageId,
pageNum: num,
xOffset,
yOffset,
widthRatio,
heightRatio,
},
});
};
2024-01-24 19:37:51 +08:00
const submitAnnotations = async (newAnnotations) => {
2024-01-24 20:18:42 +08:00
const isAnnotationSent = await presentationSubmitAnnotations({
2024-01-24 19:37:51 +08:00
variables: {
pageId: currentPresentationPage?.pageId,
annotations: newAnnotations,
},
});
2024-01-24 20:18:42 +08:00
return isAnnotationSent?.data?.presAnnotationSubmit;
2024-01-24 19:37:51 +08:00
};
const persistShapeWrapper = (shape, whiteboardId, isModerator) => {
persistShape(shape, whiteboardId, isModerator, submitAnnotations);
};
2023-10-13 00:30:39 +08:00
const isMultiUserActive = whiteboardWriters?.length > 0;
2023-10-28 00:05:43 +08:00
const { data: pollData } = useSubscription(POLL_RESULTS_SUBSCRIPTION);
const pollResults = pollData?.poll[0] || null;
2023-11-23 04:01:18 +08:00
const { data: currentUser } = useCurrentUser((user) => ({
presenter: user.presenter,
isModerator: user.isModerator,
userId: user.userId,
}));
const { data: cursorData } = useSubscription(CURSOR_SUBSCRIPTION);
const { pres_page_cursor: cursorArray } = (cursorData || []);
2024-01-25 00:53:01 +08:00
const { data: annotationStreamData } = useSubscription(
2023-09-28 10:15:33 +08:00
CURRENT_PAGE_ANNOTATIONS_STREAM,
{
variables: { lastUpdatedAt: new Date(0).toISOString() },
2023-09-28 10:26:30 +08:00
},
2023-09-28 10:15:33 +08:00
);
useEffect(() => {
const { pres_annotation_curr_stream: annotationStream } = annotationStreamData || {};
if (annotationStream) {
const newAnnotations = [];
const annotationsToBeRemoved = [];
annotationStream.forEach((item) => {
if (item.annotationInfo === '') {
annotationsToBeRemoved.push(item.annotationId);
} else {
newAnnotations.push(item);
}
});
const currentAnnotations = annotations.filter(
(annotation) => !annotationsToBeRemoved.includes(annotation.annotationId),
);
setAnnotations([...currentAnnotations, ...newAnnotations]);
2023-09-28 10:15:33 +08:00
}
}, [annotationStreamData]);
let bgShape = [];
2023-09-28 04:42:47 +08:00
2024-02-21 10:18:36 +08:00
React.useEffect(() => {
const updatedShapes = formatAnnotations(
annotations.filter((annotation) => annotation.pageId === currentPresentationPage?.pageId),
intl,
curPageId,
currentPresentationPage,
);
setShapes(updatedShapes);
}, [annotations, intl, curPageId, currentPresentationPage]);
2023-09-28 04:42:47 +08:00
const { isIphone } = deviceInfo;
const assetId = AssetRecordType.createId(curPageId);
const assets = [{
id: assetId,
typeName: "asset",
2023-09-28 04:42:47 +08:00
type: 'image',
meta: {},
props: {
w: currentPresentationPage?.scaledWidth,
h: currentPresentationPage?.scaledHeight,
src: currentPresentationPage?.svgUrl,
name: "",
isAnimated: false,
mimeType: null,
}
}];
2023-09-28 04:42:47 +08:00
const isRTL = layoutSelect((i) => i.isRTL);
const width = layoutSelect((i) => i?.output?.presentation?.width);
const height = layoutSelect((i) => i?.output?.presentation?.height);
const sidebarNavigationWidth = layoutSelect(
2023-09-28 10:26:30 +08:00
(i) => i?.output?.sidebarNavigation?.width,
2023-09-28 04:42:47 +08:00
);
2023-11-23 04:01:18 +08:00
const isPresenter = currentUser?.presenter;
const isModerator = currentUser?.isModerator;
2023-09-28 04:42:47 +08:00
const { maxStickyNoteLength, maxNumberOfAnnotations } = WHITEBOARD_CONFIG;
const fontFamily = WHITEBOARD_CONFIG.styles.text.family;
const { colorStyle, dashStyle, fillStyle, fontStyle, sizeStyle } = WHITEBOARD_CONFIG.styles;
2023-09-28 10:26:30 +08:00
const handleToggleFullScreen = (ref) => FullscreenService.toggleFullScreen(ref);
2023-09-28 04:42:47 +08:00
const layoutContextDispatch = layoutDispatch();
bgShape.push({
x: 1,
y: 1,
rotation: 0,
2023-09-28 04:42:47 +08:00
isLocked: true,
opacity: 1,
meta: {},
id: `shape:BG-${curPageId}`,
type: "image",
props: {
w: currentPresentationPage?.scaledWidth || 1,
h: currentPresentationPage?.scaledHeight || 1,
assetId: assetId,
playing: true,
url: "",
crop: null,
2023-09-28 04:42:47 +08:00
},
parentId: `page:${curPageId}`,
index: "a0",
typeName: "shape",
});
2023-09-28 04:42:47 +08:00
2023-09-28 10:26:30 +08:00
return (
<Whiteboard
{...{
isPresenter,
isModerator,
currentUser,
isRTL,
width,
height,
maxStickyNoteLength,
maxNumberOfAnnotations,
fontFamily,
colorStyle,
dashStyle,
fillStyle,
fontStyle,
sizeStyle,
2023-09-28 10:26:30 +08:00
handleToggleFullScreen,
sidebarNavigationWidth,
layoutContextDispatch,
initDefaultPages,
2024-01-24 19:37:51 +08:00
persistShapeWrapper,
2023-09-28 10:26:30 +08:00
isMultiUserActive,
shapes,
bgShape,
2023-09-28 10:26:30 +08:00
assets,
removeShapes,
zoomSlide,
2023-09-28 10:26:30 +08:00
notifyNotAllowedChange,
notifyShapeNumberExceeded,
whiteboardToolbarAutoHide:
2023-09-28 04:42:47 +08:00
SettingsService?.application?.whiteboardToolbarAutoHide,
2023-09-28 10:26:30 +08:00
animations: SettingsService?.application?.animations,
toggleToolsAnimations,
isIphone,
currentPresentationPage,
2023-10-18 00:35:48 +08:00
numberOfPages: currentPresentationPage?.totalPages,
2023-09-28 10:26:30 +08:00
presentationId,
2023-10-12 04:17:10 +08:00
hasWBAccess,
2023-10-13 00:30:39 +08:00
whiteboardWriters,
zoomChanger,
2023-09-28 10:26:30 +08:00
}}
{...props}
meetingId={Auth.meetingID}
publishCursorUpdate={CursorService.publishCursorUpdate}
otherCursors={cursorArray}
hideViewersCursor={meeting?.data?.lockSettings?.hideViewersCursor}
2023-09-28 10:26:30 +08:00
/>
);
};
2023-09-28 04:42:47 +08:00
export default WhiteboardContainer;