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

241 lines
8.0 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';
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 { useSubscription, useMutation, useLazyQuery } from '@apollo/client';
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';
const APP_CONFIG = window.meetingClientSettings.public.app;
2023-10-04 20:23:24 +08:00
const PRELOAD_NEXT_SLIDE = APP_CONFIG.preloadNextSlides;
const fetchedpresentation = {};
const PresentationContainer = (props) => {
const { data: presentationPageData } = useSubscription(CURRENT_PRESENTATION_PAGE_SUBSCRIPTION);
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 } = useSubscription(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 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 } = useSubscription(POLL_SUBSCRIPTION);
const poll = pollData?.poll[0] || {};
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,
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,
2023-10-04 21:49:59 +08:00
slidePosition,
2023-11-06 21:35:55 +08:00
downloadPresentationUri: `${APP_CONFIG.bbbWebBase}/${currentPresentationPage?.downloadFileUri}`,
2023-10-04 21:49:59 +08:00
multiUser: (multiUserData.hasAccess || multiUserData.active) && presentationIsOpen,
presentationIsDownloadable: currentPresentationPage?.downloadable,
mountPresentation: !!currentSlide,
currentPresentationId: currentPresentationPage?.presentationId,
totalPages: currentPresentationPage?.totalPages || 0,
2023-10-04 21:49:59 +08:00
notify,
zoomSlide,
2023-10-04 21:49:59 +08:00
publishedPoll: poll?.published || false,
restoreOnUpdate: getFromUserSettings(
'bbb_force_restore_presentation_on_new_events',
window.meetingClientSettings.public.presentation.restoreOnUpdate,
2023-10-04 21:49:59 +08:00
),
addWhiteboardGlobalAccess: getUsers,
removeWhiteboardGlobalAccess,
2023-10-04 21:49:59 +08:00
multiUserSize: multiUserData.size,
isViewersAnnotationsLocked,
setPresentationIsOpen: MediaService.setPresentationIsOpen,
isDefaultPresentation: currentPresentationPage?.isDefaultPresentation,
presentationName: currentPresentationPage?.presentationName,
2023-10-12 20:32:24 +08:00
presentationAreaSize,
currentUser,
}
}
/>
);
};
2023-10-04 20:23:24 +08:00
export default PresentationContainer;
PresentationContainer.propTypes = {
presentationIsOpen: PropTypes.bool.isRequired,
};