bigbluebutton-Github/bigbluebutton-html5/imports/api/slides/server/methods/switchSlide.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

import Presentations from '/imports/api/presentations';
import Slides from '/imports/api/slides';
2016-10-21 19:41:17 +08:00
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
2016-10-21 19:41:17 +08:00
export default function switchSlide(credentials, slideNumber) {
const REDIS_CONFIG = Meteor.settings.private.redis;
2016-10-21 19:41:17 +08:00
2017-10-12 08:59:35 +08:00
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'SetCurrentPagePubMsg';
2016-10-21 19:41:17 +08:00
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
check(slideNumber, Number);
2017-10-12 08:59:35 +08:00
const selector = {
2016-10-21 19:41:17 +08:00
meetingId,
2017-10-12 08:59:35 +08:00
current: true,
};
const Presentation = Presentations.findOne(selector);
2016-10-21 19:41:17 +08:00
if (!Presentation) {
2018-01-08 08:25:56 +08:00
throw new Meteor.Error('presentation-not-found', 'You need a presentation to be able to switch slides');
2016-10-21 19:41:17 +08:00
}
const Slide = Slides.findOne({
meetingId,
2017-10-12 08:59:35 +08:00
presentationId: Presentation.id,
num: slideNumber,
2016-10-21 19:41:17 +08:00
});
if (!Slide) {
2018-01-08 08:25:56 +08:00
throw new Meteor.Error('slide-not-found', `Slide number ${slideNumber} not found in the current presentation`);
2016-10-21 19:41:17 +08:00
}
2017-06-03 03:25:02 +08:00
const payload = {
2017-10-12 08:59:35 +08:00
pageId: Slide.id,
presentationId: Presentation.id,
2016-10-21 19:41:17 +08:00
};
2017-10-12 08:59:35 +08:00
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
2017-06-03 03:25:02 +08:00
}