2021-04-07 03:58:11 +08:00
|
|
|
import React, { useContext } from 'react';
|
2018-01-08 12:44:42 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2020-05-12 20:58:14 +08:00
|
|
|
import MediaService, { getSwapLayout, shouldEnableSwapLayout } from '/imports/ui/components/media/service';
|
2019-05-10 01:44:54 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { Session } from 'meteor/session';
|
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';
|
2019-07-18 08:30:28 +08:00
|
|
|
import PresentationToolbarService from './presentation-toolbar/service';
|
2021-04-07 03:58:11 +08:00
|
|
|
import { UsersContext } from '../components-data/users-context/context';
|
2020-05-12 20:58:14 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import getFromUserSettings from '/imports/ui/services/users-settings';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { NLayoutContext } from '../layout/context/context';
|
2021-03-05 06:26:25 +08:00
|
|
|
import WhiteboardService from '/imports/ui/components/whiteboard/service';
|
2020-05-12 20:58:14 +08:00
|
|
|
|
|
|
|
const ROLE_VIEWER = Meteor.settings.public.user.role_viewer;
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2021-06-09 21:49:59 +08:00
|
|
|
const PresentationContainer = ({ presentationPodIds, mountPresentation, ...props }) => {
|
2021-07-06 19:28:17 +08:00
|
|
|
const fullscreenElementId = 'Presentation';
|
2021-05-18 04:25:07 +08:00
|
|
|
const newLayoutContext = useContext(NLayoutContext);
|
2021-05-25 01:05:39 +08:00
|
|
|
const { newLayoutContextState, newLayoutContextDispatch } = newLayoutContext;
|
2021-07-17 03:54:23 +08:00
|
|
|
const { output, layoutLoaded, layoutType, fullscreen } = newLayoutContextState;
|
2021-05-25 01:05:39 +08:00
|
|
|
const { presentation } = output;
|
2021-07-13 03:47:06 +08:00
|
|
|
const { element } = fullscreen;
|
2021-07-06 19:28:17 +08:00
|
|
|
const fullscreenContext = (element === fullscreenElementId);
|
2021-04-20 01:54:14 +08:00
|
|
|
const { layoutSwapped, podId } = props;
|
|
|
|
|
2021-04-07 03:58:11 +08:00
|
|
|
const usingUsersContext = useContext(UsersContext);
|
|
|
|
const { users } = usingUsersContext;
|
2021-04-15 20:12:21 +08:00
|
|
|
const currentUser = users[Auth.meetingID][Auth.userID];
|
2021-04-20 01:54:14 +08:00
|
|
|
|
|
|
|
const userIsPresenter = (podId === 'DEFAULT_PRESENTATION_POD') ? currentUser.presenter : props.isPresenter;
|
|
|
|
|
2021-06-09 21:49:59 +08:00
|
|
|
return mountPresentation
|
2021-04-07 03:58:11 +08:00
|
|
|
&& (
|
2021-06-09 21:49:59 +08:00
|
|
|
<Presentation
|
2021-04-07 03:58:11 +08:00
|
|
|
{
|
|
|
|
...{
|
2021-05-18 04:25:07 +08:00
|
|
|
newLayoutContextDispatch,
|
2021-04-07 03:58:11 +08:00
|
|
|
...props,
|
|
|
|
isViewer: currentUser.role === ROLE_VIEWER,
|
2021-04-20 01:54:14 +08:00
|
|
|
userIsPresenter: userIsPresenter && !layoutSwapped,
|
2021-05-25 01:05:39 +08:00
|
|
|
presentationBounds: presentation,
|
|
|
|
layoutLoaded,
|
2021-07-17 03:54:23 +08:00
|
|
|
layoutType,
|
2021-06-25 02:42:45 +08:00
|
|
|
fullscreenContext,
|
2021-07-06 19:28:17 +08:00
|
|
|
fullscreenElementId,
|
2021-04-07 03:58:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2020-04-08 05:19:16 +08:00
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
|
|
|
const PRELOAD_NEXT_SLIDE = APP_CONFIG.preloadNextSlides;
|
|
|
|
const fetchedpresentation = {};
|
2020-04-14 01:43:35 +08:00
|
|
|
|
2018-07-27 03:35:38 +08:00
|
|
|
export default withTracker(({ podId }) => {
|
2021-06-09 21:49:59 +08:00
|
|
|
const currentSlide = PresentationService.getCurrentSlide(podId);
|
|
|
|
const presentationIsDownloadable = PresentationService.isPresentationDownloadable(podId);
|
2019-08-14 01:41:47 +08:00
|
|
|
const layoutSwapped = getSwapLayout() && shouldEnableSwapLayout();
|
2019-08-01 03:10:41 +08:00
|
|
|
|
2019-08-02 01:50:39 +08:00
|
|
|
let slidePosition;
|
2019-08-01 03:10:41 +08:00
|
|
|
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] = {
|
2020-04-14 01:43:35 +08:00
|
|
|
canFetch: true,
|
2020-04-08 05:19:16 +08:00
|
|
|
fetchedSlide: {},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const currentSlideNum = currentSlide.num;
|
|
|
|
const presentation = fetchedpresentation[presentationId];
|
2020-04-14 01:43:35 +08:00
|
|
|
|
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) => {
|
2020-04-14 01:43:35 +08:00
|
|
|
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
|
|
|
}
|
2019-08-01 03:10:41 +08:00
|
|
|
}
|
2021-05-18 04:25:07 +08:00
|
|
|
|
|
|
|
const layoutManagerLoaded = Session.get('layoutManagerLoaded');
|
2018-07-27 03:35:38 +08:00
|
|
|
return {
|
|
|
|
currentSlide,
|
2019-08-01 03:10:41 +08:00
|
|
|
slidePosition,
|
2021-06-09 21:49:59 +08:00
|
|
|
downloadPresentationUri: PresentationService.downloadPresentationUri(podId),
|
|
|
|
isPresenter: PresentationService.isPresenter(podId),
|
2021-03-05 06:26:25 +08:00
|
|
|
multiUser: WhiteboardService.hasMultiUserAccess(currentSlide && currentSlide.id, Auth.userID)
|
2019-08-14 01:41:47 +08:00
|
|
|
&& !layoutSwapped,
|
2019-02-21 01:17:17 +08:00
|
|
|
presentationIsDownloadable,
|
2021-06-09 21:49:59 +08:00
|
|
|
mountPresentation: !!currentSlide,
|
|
|
|
currentPresentation: PresentationService.getCurrentPresentation(podId),
|
2019-05-10 01:44:54 +08:00
|
|
|
notify,
|
2019-07-18 08:30:28 +08:00
|
|
|
zoomSlide: PresentationToolbarService.zoomSlide,
|
2020-01-25 09:02:36 +08:00
|
|
|
podId,
|
2020-05-12 20:58:14 +08:00
|
|
|
layoutSwapped,
|
|
|
|
toggleSwapLayout: MediaService.toggleSwapLayout,
|
|
|
|
publishedPoll: Meetings.findOne({ meetingId: Auth.meetingID }, {
|
|
|
|
fields: {
|
|
|
|
publishedPoll: 1,
|
|
|
|
},
|
|
|
|
}).publishedPoll,
|
2020-05-15 05:06:55 +08:00
|
|
|
currentPresentationId: Session.get('currentPresentationId') || null,
|
2020-05-12 20:58:14 +08:00
|
|
|
restoreOnUpdate: getFromUserSettings(
|
|
|
|
'bbb_force_restore_presentation_on_new_events',
|
|
|
|
Meteor.settings.public.presentation.restoreOnUpdate,
|
|
|
|
),
|
2021-05-18 04:25:07 +08:00
|
|
|
layoutManagerLoaded,
|
2018-07-27 03:35:38 +08:00
|
|
|
};
|
2021-06-09 21:49:59 +08:00
|
|
|
})(PresentationContainer);
|