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

143 lines
5.0 KiB
React
Raw Normal View History

import React, { useContext } from 'react';
import { withTracker } from 'meteor/react-meteor-data';
import { notify } from '/imports/ui/services/notification';
2021-06-09 21:49:59 +08:00
import PresentationService from './service';
2020-04-08 05:19:16 +08:00
import { Slides } from '/imports/api/slides';
2021-06-09 21:49:59 +08:00
import Presentation from '/imports/ui/components/presentation/component';
import PresentationToolbarService from './presentation-toolbar/service';
import { UsersContext } from '../components-data/users-context/context';
import Auth from '/imports/ui/services/auth';
import Meetings from '/imports/api/meetings';
import getFromUserSettings from '/imports/ui/services/users-settings';
2021-09-11 04:48:52 +08:00
import {
layoutSelect,
layoutSelectInput,
layoutSelectOutput,
layoutDispatch,
} from '../layout/context';
2022-06-02 23:00:28 +08:00
import lockContextContainer from "/imports/ui/components/lock-viewers/context/container";
import WhiteboardService from '/imports/ui/components/whiteboard/service';
import { DEVICE_TYPE } from '../layout/enums';
const PresentationContainer = ({ presentationIsOpen, presentationPodIds, mountPresentation, ...props }) => {
2021-09-11 04:48:52 +08:00
const cameraDock = layoutSelectInput((i) => i.cameraDock);
const presentation = layoutSelectOutput((i) => i.presentation);
const layoutType = layoutSelect((i) => i.layoutType);
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));
const usingUsersContext = useContext(UsersContext);
const { users } = usingUsersContext;
2021-04-15 20:12:21 +08:00
const currentUser = users[Auth.meetingID][Auth.userID];
const userIsPresenter = currentUser.presenter;
return (
<Presentation
{
...{
layoutContextDispatch,
numCameras,
...props,
userIsPresenter,
presentationBounds: presentation,
layoutType,
fullscreenContext,
fullscreenElementId,
isMobile: deviceType === DEVICE_TYPE.MOBILE,
isIphone,
presentationIsOpen,
}
}
/>
);
};
2020-04-08 05:19:16 +08:00
const APP_CONFIG = Meteor.settings.public.app;
const PRELOAD_NEXT_SLIDE = APP_CONFIG.preloadNextSlides;
const fetchedpresentation = {};
2022-06-02 23:00:28 +08:00
export default lockContextContainer(
withTracker(({ podId, presentationIsOpen, userLocks }) => {
2021-06-09 21:49:59 +08:00
const currentSlide = PresentationService.getCurrentSlide(podId);
const presentationIsDownloadable = PresentationService.isPresentationDownloadable(podId);
2022-06-02 23:00:28 +08:00
const isViewersCursorLocked = userLocks?.hideViewersCursor;
2019-08-02 01:50:39 +08:00
let slidePosition;
if (currentSlide) {
const {
presentationId,
id: slideId,
} = currentSlide;
2021-06-09 21:49:59 +08:00
slidePosition = PresentationService.getSlidePosition(podId, presentationId, slideId);
2020-04-08 05:24:09 +08:00
if (PRELOAD_NEXT_SLIDE && !fetchedpresentation[presentationId]) {
2020-04-08 05:19:16 +08:00
fetchedpresentation[presentationId] = {
canFetch: true,
2020-04-08 05:19:16 +08:00
fetchedSlide: {},
};
}
const currentSlideNum = currentSlide.num;
const presentation = fetchedpresentation[presentationId];
2021-05-18 04:25:07 +08:00
if (PRELOAD_NEXT_SLIDE
&& !presentation.fetchedSlide[currentSlide.num + PRELOAD_NEXT_SLIDE]
&& presentation.canFetch) {
2020-04-08 05:19:16 +08:00
const slidesToFetch = Slides.find({
podId,
presentationId,
num: {
$in: Array(PRELOAD_NEXT_SLIDE).fill(1).map((v, idx) => currentSlideNum + (idx + 1)),
},
}).fetch();
const promiseImageGet = slidesToFetch
2021-05-18 04:25:07 +08:00
.filter((s) => !fetchedpresentation[presentationId].fetchedSlide[s.num])
2020-04-08 05:19:16 +08:00
.map(async (slide) => {
if (presentation.canFetch) presentation.canFetch = false;
2020-04-08 05:19:16 +08:00
const image = await fetch(slide.imageUri);
if (image.ok) {
presentation.fetchedSlide[slide.num] = true;
}
});
2021-05-18 04:25:07 +08:00
Promise.all(promiseImageGet).then(() => {
presentation.canFetch = true;
});
2020-04-08 05:19:16 +08:00
}
}
2021-05-18 04:25:07 +08:00
2018-07-27 03:35:38 +08:00
return {
currentSlide,
slidePosition,
2021-06-09 21:49:59 +08:00
downloadPresentationUri: PresentationService.downloadPresentationUri(podId),
multiUser: (WhiteboardService.hasMultiUserAccess(currentSlide && currentSlide.id, Auth.userID) || WhiteboardService.isMultiUserActive(currentSlide?.id))
&& presentationIsOpen,
presentationIsDownloadable,
2021-06-09 21:49:59 +08:00
mountPresentation: !!currentSlide,
currentPresentation: PresentationService.getCurrentPresentation(podId),
notify,
zoomSlide: PresentationToolbarService.zoomSlide,
podId,
publishedPoll: Meetings.findOne({ meetingId: Auth.meetingID }, {
fields: {
publishedPoll: 1,
},
}).publishedPoll,
restoreOnUpdate: getFromUserSettings(
'bbb_force_restore_presentation_on_new_events',
Meteor.settings.public.presentation.restoreOnUpdate,
),
addWhiteboardGlobalAccess: WhiteboardService.addGlobalAccess,
removeWhiteboardGlobalAccess: WhiteboardService.removeGlobalAccess,
multiUserSize: WhiteboardService.getMultiUserSize(currentSlide?.id),
2022-06-02 23:00:28 +08:00
isViewersCursorLocked,
2018-07-27 03:35:38 +08:00
};
2022-06-02 23:00:28 +08:00
})(PresentationContainer));