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

100 lines
3.8 KiB
React
Raw Normal View History

import React from 'react';
import { withTracker } from 'meteor/react-meteor-data';
import MediaService, { getSwapLayout, shouldEnableSwapLayout } from '/imports/ui/components/media/service';
import { notify } from '/imports/ui/services/notification';
2017-02-17 05:11:46 +08:00
import PresentationAreaService from './service';
2020-04-08 05:19:16 +08:00
import { Slides } from '/imports/api/slides';
2017-02-17 05:11:46 +08:00
import PresentationArea from './component';
import PresentationToolbarService from './presentation-toolbar/service';
import Auth from '/imports/ui/services/auth';
import Meetings from '/imports/api/meetings';
import Users from '/imports/api/users';
import getFromUserSettings from '/imports/ui/services/users-settings';
import WhiteboardService from '/imports/ui/components/whiteboard/service';
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
2019-03-07 05:57:07 +08:00
const PresentationAreaContainer = ({ presentationPodIds, mountPresentationArea, ...props }) => (
mountPresentationArea && <PresentationArea {...props} />
);
2020-04-08 05:19:16 +08:00
const APP_CONFIG = Meteor.settings.public.app;
const PRELOAD_NEXT_SLIDE = APP_CONFIG.preloadNextSlides;
const fetchedpresentation = {};
2018-07-27 03:35:38 +08:00
export default withTracker(({ podId }) => {
const currentSlide = PresentationAreaService.getCurrentSlide(podId);
const presentationIsDownloadable = PresentationAreaService.isPresentationDownloadable(podId);
const layoutSwapped = getSwapLayout() && shouldEnableSwapLayout();
const isViewer = Users.findOne({ meetingId: Auth.meetingID, userId: Auth.userID }, {
fields: {
role: 1,
},
}).role === ROLE_VIEWER;
2019-08-02 01:50:39 +08:00
let slidePosition;
if (currentSlide) {
const {
presentationId,
id: slideId,
} = currentSlide;
slidePosition = PresentationAreaService.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];
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
.filter(s => !fetchedpresentation[presentationId].fetchedSlide[s.num])
.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;
}
});
Promise.all(promiseImageGet).then(() => presentation.canFetch = true);
2020-04-08 05:19:16 +08:00
}
}
2018-07-27 03:35:38 +08:00
return {
currentSlide,
slidePosition,
downloadPresentationUri: PresentationAreaService.downloadPresentationUri(podId),
userIsPresenter: PresentationAreaService.isPresenter(podId) && !layoutSwapped,
multiUser: WhiteboardService.hasMultiUserAccess(currentSlide && currentSlide.id, Auth.userID)
&& !layoutSwapped,
presentationIsDownloadable,
2019-03-07 05:57:07 +08:00
mountPresentationArea: !!currentSlide,
currentPresentation: PresentationAreaService.getCurrentPresentation(podId),
notify,
zoomSlide: PresentationToolbarService.zoomSlide,
podId,
layoutSwapped,
toggleSwapLayout: MediaService.toggleSwapLayout,
publishedPoll: Meetings.findOne({ meetingId: Auth.meetingID }, {
fields: {
publishedPoll: 1,
},
}).publishedPoll,
isViewer,
currentPresentationId: Session.get('currentPresentationId') || null,
restoreOnUpdate: getFromUserSettings(
'bbb_force_restore_presentation_on_new_events',
Meteor.settings.public.presentation.restoreOnUpdate,
),
2018-07-27 03:35:38 +08:00
};
})(PresentationAreaContainer);