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

71 lines
1.7 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';
export default async function setCurrentPresentation(meetingId, podId, presentationId) {
2016-11-12 03:02:46 +08:00
check(meetingId, String);
check(presentationId, String);
check(podId, String);
2016-11-12 03:02:46 +08:00
const oldCurrent = {
selector: {
meetingId,
podId,
2017-10-12 08:40:51 +08:00
current: true,
id: {
$ne: presentationId,
},
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) {
Logger.error(`Unsetting the current presentation: ${err}`);
return;
2016-11-12 03:02:46 +08:00
}
Logger.info('Unsetted as current presentation');
2016-11-12 03:02:46 +08:00
},
};
const newCurrent = {
selector: {
meetingId,
podId,
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) {
Logger.error(`Setting as current presentation id=${presentationId}: ${err}`);
return;
2016-11-12 03:02:46 +08:00
}
Logger.info(`Setted as current presentation id=${presentationId}`);
2016-11-12 03:02:46 +08:00
},
};
const oldPresentation = await Presentations.findOneAsync(oldCurrent.selector);
const newPresentation = await Presentations.findOneAsync(newCurrent.selector);
2023-03-04 01:58:41 +08:00
// We update it before unset current to avoid the case where theres no current presentation.
if (newPresentation) {
try{
await Presentations.updateAsync(newPresentation._id, newCurrent.modifier);
} catch(e){
2023-03-04 01:58:41 +08:00
newCurrent.callback(e);
}
2017-10-12 08:40:51 +08:00
}
2023-03-04 01:58:41 +08:00
if (oldPresentation) {
try {
await Presentations.updateAsync(oldCurrent.selector, oldCurrent.modifier, { multi: true });
} catch (e) {
2023-03-04 01:58:41 +08:00
oldCurrent.callback(e);
}
2016-11-12 03:02:46 +08:00
}
2023-03-04 01:58:41 +08:00
2017-06-03 03:25:02 +08:00
}