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

47 lines
1.4 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';
import { extractCredentials } from '/imports/api/common/server/helpers';
2016-10-21 19:41:17 +08:00
export default function switchSlide(slideNumber, podId) { // TODO-- send presentationId and SlideId
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';
const { meetingId, requesterUserId } = extractCredentials(this.userId);
2016-10-21 19:41:17 +08:00
check(slideNumber, Number);
2017-10-12 08:59:35 +08:00
const selector = {
2016-10-21 19:41:17 +08:00
meetingId,
podId,
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,
podId,
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 = {
podId,
2017-10-12 08:59:35 +08:00
presentationId: Presentation.id,
pageId: Slide.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
}