bigbluebutton-Github/bigbluebutton-html5/imports/api/presentation-pods/server/modifiers/addPresentationPod.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

import { Match, check } from 'meteor/check';
import PresentationPods from '/imports/api/presentation-pods';
import Logger from '/imports/startup/server/logger';
2018-04-06 06:29:58 +08:00
import addPresentation from '/imports/api/presentations/server/modifiers/addPresentation';
// 'presentations' is passed down here when we receive a Sync message
// and it's not used when we just create a new presentation pod
export default async function addPresentationPod(meetingId, pod, presentations = undefined) {
check(meetingId, String);
2018-04-06 06:29:58 +08:00
check(presentations, Match.Maybe(Array));
check(pod, {
currentPresenterId: String,
podId: String,
});
const { currentPresenterId, podId } = pod;
const selector = {
meetingId,
podId,
};
const modifier = {
meetingId,
podId,
currentPresenterId,
};
try {
const { insertedId } = await PresentationPods.upsertAsync(selector, modifier);
// if it's a Sync message - continue adding the attached presentations
2018-04-06 06:29:58 +08:00
if (presentations) {
presentations.forEach(async (presentation) =>
addPresentation(meetingId, podId, presentation));
2018-04-06 06:29:58 +08:00
}
if (insertedId) {
Logger.info(`Added presentation pod id=${podId} meeting=${meetingId}`);
} else {
Logger.info(`Upserted presentation pod id=${podId} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Adding presentation pod to the collection: ${err}`);
}
}