2017-06-29 03:05:50 +08:00
|
|
|
import Presentations from '/imports/api/2.0/presentations';
|
|
|
|
import Slides from '/imports/api/2.0/slides';
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
2017-07-01 03:16:00 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis2x';
|
2017-06-29 03:05:50 +08:00
|
|
|
|
|
|
|
export default function switchSlide(credentials, slideNumber) {
|
|
|
|
const REDIS_CONFIG = Meteor.settings.redis;
|
|
|
|
|
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.presentation;
|
|
|
|
const EVENT_NAME = 'go_to_slide';
|
|
|
|
|
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
check(slideNumber, Number);
|
|
|
|
|
|
|
|
const Presentation = Presentations.findOne({
|
|
|
|
meetingId,
|
|
|
|
'presentation.current': true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!Presentation) {
|
|
|
|
throw new Meteor.Error(
|
|
|
|
'presentation-not-found', 'You need a presentation to be able to switch slides');
|
|
|
|
}
|
|
|
|
|
|
|
|
const Slide = Slides.findOne({
|
|
|
|
meetingId,
|
|
|
|
presentationId: Presentation.presentation.id,
|
|
|
|
'slide.num': parseInt(slideNumber, 2),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!Slide) {
|
|
|
|
throw new Meteor.Error(
|
|
|
|
'slide-not-found', `Slide number ${slideNumber} not found in the current presentation`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
page: Slide.slide.id,
|
|
|
|
meeting_id: meetingId,
|
|
|
|
};
|
|
|
|
|
|
|
|
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
|
|
|
|
}
|