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

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-11-12 03:02:46 +08:00
import { check } from 'meteor/check';
2017-06-19 19:57:32 +08:00
import Presentations from './../../';
2016-11-12 03:02:46 +08:00
import Logger from '/imports/startup/server/logger';
export default function changeCurrentPresentation(meetingId, presentationId) {
check(meetingId, String);
check(presentationId, String);
const oldCurrent = {
selector: {
meetingId,
'presentation.current': true,
},
modifier: {
$set: { 'presentation.current': false },
},
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,
'presentation.id': presentationId,
},
modifier: {
$set: { 'presentation.current': true },
},
callback: (err) => {
if (err) {
return Logger.error(`Setting as current presentation id=${presentationId}: ${err}`);
}
return Logger.info(`Setted as current presentation id=${presentationId}`);
},
};
const oldPresentation = Presentations.findOne(oldCurrent.selector);
const newPresentation = Presentations.findOne(newCurrent.selector);
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
}