bigbluebutton-Github/bigbluebutton-html5/imports/api/presentations/server/modifiers/setCurrentPresentation.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-11-12 03:02:46 +08:00
import { check } from 'meteor/check';
import Presentations from '/imports/api/presentations';
2016-11-12 03:02:46 +08:00
import Logger from '/imports/startup/server/logger';
2017-10-12 08:40:51 +08:00
export default function setCurrentPresentation(meetingId, presentationId) {
2016-11-12 03:02:46 +08:00
check(meetingId, String);
check(presentationId, String);
const oldCurrent = {
selector: {
meetingId,
2017-10-12 08:40:51 +08:00
current: true,
2016-11-12 03:02:46 +08:00
},
modifier: {
2017-10-12 08:40:51 +08:00
$set: { current: false },
2016-11-12 03:02:46 +08:00
},
callback: (err) => {
if (err) {
return Logger.error(`Unsetting the current presentation: ${err}`);
}
2017-06-03 03:25:02 +08:00
return Logger.info('Unsetted as current presentation');
2016-11-12 03:02:46 +08:00
},
};
const newCurrent = {
selector: {
meetingId,
2017-10-12 08:40:51 +08:00
id: presentationId,
2016-11-12 03:02:46 +08:00
},
modifier: {
2017-10-12 08:40:51 +08:00
$set: { current: true },
2016-11-12 03:02:46 +08:00
},
callback: (err) => {
if (err) {
return Logger.error(`Setting as current presentation id=${presentationId}: ${err}`);
2016-11-12 03:02:46 +08:00
}
return Logger.info(`Setted as current presentation id=${presentationId}`);
2016-11-12 03:02:46 +08:00
},
};
const oldPresentation = Presentations.findOne(oldCurrent.selector);
const newPresentation = Presentations.findOne(newCurrent.selector);
2017-10-12 08:40:51 +08:00
// Prevent bug with presentation being unset, same happens in the slide
// See: https://github.com/bigbluebutton/bigbluebutton/pull/4431
if (oldPresentation && newPresentation && (oldPresentation._id === newPresentation._id)) {
return;
}
2016-11-12 03:02:46 +08:00
if (newPresentation) {
Presentations.update(newPresentation._id, newCurrent.modifier, newCurrent.callback);
}
if (oldPresentation) {
Presentations.update(oldPresentation._id, oldCurrent.modifier, oldCurrent.callback);
}
2017-06-03 03:25:02 +08:00
}