bigbluebutton-Github/bigbluebutton-html5/imports/api/presentations/server/methods/exportPresentation.js

62 lines
2.0 KiB
JavaScript
Raw Normal View History

import RedisPubSub from '/imports/startup/server/redis';
import { check } from 'meteor/check';
import { extractCredentials } from '/imports/api/common/server/helpers';
import Logger from '/imports/startup/server/logger';
import setPresentationExporting from '/imports/api/presentations/server/modifiers/setPresentationExporting';
import Presentations from '/imports/api/presentations';
const EXPORTING_THRESHOLD_PER_SLIDE = 2500;
2023-08-18 21:57:50 +08:00
export default async function exportPresentation(presentationId, fileStateType) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'MakePresentationDownloadReqMsg';
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
check(presentationId, String);
const payload = {
presId: presentationId,
allPages: true,
2023-08-18 21:57:50 +08:00
fileStateType,
pages: [],
};
const setObserver = async () => {
let timeoutRef = null;
2022-07-25 20:35:08 +08:00
const selector = { meetingId, id: presentationId };
const cursor = Presentations.find(selector);
const pres = await Presentations.findOneAsync(selector);
const numPages = pres?.pages?.length ?? 1;
2022-07-26 05:56:26 +08:00
const threshold = EXPORTING_THRESHOLD_PER_SLIDE * numPages;
const observer = cursor.observe({
changed: (doc) => {
2022-07-26 05:56:26 +08:00
const { status } = doc.exportation;
2022-07-26 05:56:26 +08:00
if (status === 'EXPORTED') {
Meteor.clearTimeout(timeoutRef);
}
},
});
timeoutRef = Meteor.setTimeout(async () => {
observer.stop();
await setPresentationExporting(meetingId, presentationId, { status: 'TIMEOUT' });
2022-07-26 05:56:26 +08:00
}, threshold);
};
await setPresentationExporting(meetingId, presentationId, { status: 'RUNNING' });
await setObserver();
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} catch (err) {
Logger.error(`Exception while invoking method exportPresentation ${err.stack}`);
}
}