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

252 lines
8.4 KiB
React
Raw Normal View History

import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { notify } from '/imports/ui/services/notification';
2021-06-09 21:49:59 +08:00
import Presentation from '/imports/ui/components/presentation/component';
import Auth from '/imports/ui/services/auth';
import getFromUserSettings from '/imports/ui/services/users-settings';
import { useMutation, useLazyQuery } from '@apollo/client';
2021-09-11 04:48:52 +08:00
import {
layoutSelect,
layoutSelectInput,
layoutSelectOutput,
layoutDispatch,
} from '../layout/context';
import { DEVICE_TYPE } from '../layout/enums';
import MediaService from '../media/service';
import {
CURRENT_PRESENTATION_PAGE_SUBSCRIPTION,
CURRENT_PAGE_WRITERS_SUBSCRIPTION,
} from '/imports/ui/components/whiteboard/queries';
import POLL_SUBSCRIPTION from '/imports/ui/core/graphql/queries/pollSubscription';
2023-10-03 21:24:38 +08:00
import useMeeting from '/imports/ui/core/hooks/useMeeting';
2023-11-23 04:01:18 +08:00
import useCurrentUser from '/imports/ui/core/hooks/useCurrentUser';
import { PRESENTATION_SET_ZOOM, PRESENTATION_SET_WRITERS } from './mutations';
import { GET_USER_IDS } from '/imports/ui/core/graphql/queries/users';
import useDeduplicatedSubscription from '../../core/hooks/useDeduplicatedSubscription';
2023-10-04 20:23:24 +08:00
const fetchedpresentation = {};
const PresentationContainer = (props) => {
const { data: presentationPageData } = useDeduplicatedSubscription(
CURRENT_PRESENTATION_PAGE_SUBSCRIPTION,
);
2023-10-04 20:23:24 +08:00
const { pres_page_curr: presentationPageArray } = (presentationPageData || {});
const currentPresentationPage = presentationPageArray && presentationPageArray[0];
const slideSvgUrl = currentPresentationPage && currentPresentationPage.svgUrl;
2023-10-04 20:23:24 +08:00
const { data: whiteboardWritersData } = useDeduplicatedSubscription(
CURRENT_PAGE_WRITERS_SUBSCRIPTION,
{
variables: { pageId: currentPresentationPage?.pageId },
skip: !currentPresentationPage?.pageId,
},
);
2023-10-04 20:23:24 +08:00
const whiteboardWriters = whiteboardWritersData?.pres_page_writers || [];
const [presentationSetZoom] = useMutation(PRESENTATION_SET_ZOOM);
const [presentationSetWriters] = useMutation(PRESENTATION_SET_WRITERS);
const [getUsers, { data: usersData }] = useLazyQuery(GET_USER_IDS, { fetchPolicy: 'no-cache' });
const users = usersData?.user || [];
const APP_CONFIG = window.meetingClientSettings.public.app;
const PRELOAD_NEXT_SLIDE = APP_CONFIG.preloadNextSlides;
const addWhiteboardGlobalAccess = () => {
const usersIds = users.map((user) => user.userId);
const { pageId } = currentPresentationPage;
presentationSetWriters({
variables: {
pageId,
usersIds,
},
});
};
// users will only be fetched when getUsers is called
useEffect(() => {
if (users.length > 0) {
addWhiteboardGlobalAccess();
}
}, [users]);
const removeWhiteboardGlobalAccess = () => {
const { pageId } = currentPresentationPage;
presentationSetWriters({
variables: {
pageId,
usersIds: [],
},
});
};
const zoomSlide = (widthRatio, heightRatio, xOffset, yOffset) => {
const { presentationId, pageId, num } = currentPresentationPage;
presentationSetZoom({
variables: {
presentationId,
pageId,
pageNum: num,
xOffset,
yOffset,
widthRatio,
heightRatio,
},
});
};
2023-10-04 20:23:24 +08:00
const meeting = useMeeting((m) => ({
lockSettings: m?.lockSettings,
}));
const isViewersAnnotationsLocked = meeting ? meeting.lockSettings?.hideViewersAnnotation : true;
2023-10-04 21:49:59 +08:00
2023-10-04 20:23:24 +08:00
const multiUserData = {
active: whiteboardWriters?.length > 0,
size: whiteboardWriters?.length || 0,
hasAccess: whiteboardWriters?.some((writer) => writer.userId === Auth.userID),
};
const { data: pollData } = useDeduplicatedSubscription(POLL_SUBSCRIPTION);
2023-10-04 20:23:24 +08:00
const poll = pollData?.poll[0] || {};
2024-06-13 22:18:07 +08:00
const hasPoll = pollData?.poll?.length > 0;
2023-10-04 20:23:24 +08:00
const currentSlide = currentPresentationPage ? {
content: currentPresentationPage.content,
current: currentPresentationPage.isCurrentPage,
height: currentPresentationPage.height,
width: currentPresentationPage.width,
id: currentPresentationPage.pageId,
imageUri: slideSvgUrl,
2023-10-04 20:23:24 +08:00
num: currentPresentationPage?.num,
presentationId: currentPresentationPage?.presentationId,
svgUri: slideSvgUrl,
2024-07-06 04:09:19 +08:00
infiniteWhiteboard: currentPresentationPage.infiniteWhiteboard,
2023-10-04 20:23:24 +08:00
} : null;
let slidePosition;
if (currentSlide) {
const { presentationId } = currentSlide;
slidePosition = {
height: currentPresentationPage.scaledHeight,
id: currentPresentationPage.pageId,
presentationId: currentPresentationPage.presentationId,
viewBoxHeight: currentPresentationPage.scaledViewBoxHeight,
viewBoxWidth: currentPresentationPage.scaledViewBoxWidth,
width: currentPresentationPage.scaledWidth,
x: currentPresentationPage.xOffset,
y: currentPresentationPage.yOffset,
};
if (PRELOAD_NEXT_SLIDE && !fetchedpresentation[presentationId]) {
fetchedpresentation[presentationId] = {
canFetch: true,
fetchedSlide: {},
};
}
const presentation = fetchedpresentation[presentationId];
if (PRELOAD_NEXT_SLIDE
&& !presentation.fetchedSlide[currentSlide.num + PRELOAD_NEXT_SLIDE]
&& presentation.canFetch) {
// TODO: preload next slides should be reimplemented in graphql
const slidesToFetch = [currentPresentationPage];
const promiseImageGet = slidesToFetch
.filter((s) => !fetchedpresentation[presentationId].fetchedSlide[s.num])
.map(async (slide) => {
if (presentation.canFetch) presentation.canFetch = false;
const image = await fetch(slide.svgUrl);
2023-10-04 20:23:24 +08:00
if (image.ok) {
presentation.fetchedSlide[slide.num] = true;
}
});
Promise.all(promiseImageGet).then(() => {
presentation.canFetch = true;
});
}
}
const { presentationIsOpen } = props;
2021-09-11 04:48:52 +08:00
const cameraDock = layoutSelectInput((i) => i.cameraDock);
const presentation = layoutSelectOutput((i) => i.presentation);
const fullscreen = layoutSelect((i) => i.fullscreen);
const deviceType = layoutSelect((i) => i.deviceType);
const layoutContextDispatch = layoutDispatch();
const { numCameras } = cameraDock;
const { element } = fullscreen;
const fullscreenElementId = 'Presentation';
2021-07-06 19:28:17 +08:00
const fullscreenContext = (element === fullscreenElementId);
2021-08-28 02:32:56 +08:00
const isIphone = !!(navigator.userAgent.match(/iPhone/i));
2023-11-23 04:01:18 +08:00
const { data: currentUser } = useCurrentUser((user) => ({
presenter: user.presenter,
userId: user.userId,
isModerator: user.isModerator,
2023-11-23 04:01:18 +08:00
}));
const userIsPresenter = currentUser?.presenter;
2023-10-12 20:32:24 +08:00
const presentationAreaSize = {
presentationAreaWidth: presentation?.width,
presentationAreaHeight: presentation?.height,
};
return (
<Presentation
{
...{
layoutContextDispatch,
numCameras,
...props,
userIsPresenter,
presentationBounds: presentation,
fullscreenContext,
fullscreenElementId,
isMobile: deviceType === DEVICE_TYPE.MOBILE,
isIphone,
currentSlide,
slidePosition,
downloadPresentationUri: `${APP_CONFIG.bbbWebBase}/${currentPresentationPage?.downloadFileUri}`,
multiUser: (multiUserData.hasAccess || multiUserData.active) && presentationIsOpen,
presentationIsDownloadable: currentPresentationPage?.downloadable,
mountPresentation: !!currentSlide,
currentPresentationId: currentPresentationPage?.presentationId,
totalPages: currentPresentationPage?.totalPages || 0,
notify,
zoomSlide,
publishedPoll: poll?.published || false,
restoreOnUpdate: getFromUserSettings(
'bbb_force_restore_presentation_on_new_events',
window.meetingClientSettings.public.presentation.restoreOnUpdate,
),
addWhiteboardGlobalAccess: getUsers,
removeWhiteboardGlobalAccess,
multiUserSize: multiUserData.size,
isViewersAnnotationsLocked,
setPresentationIsOpen: MediaService.setPresentationIsOpen,
isDefaultPresentation: currentPresentationPage?.isDefaultPresentation,
presentationName: currentPresentationPage?.presentationName,
presentationAreaSize,
currentUser,
hasPoll,
currentPresentationPage,
}
}
/>
);
};
2023-10-04 20:23:24 +08:00
export default PresentationContainer;
PresentationContainer.propTypes = {
presentationIsOpen: PropTypes.bool.isRequired,
};