2016-11-16 00:19:33 +08:00
|
|
|
import Presentations from '/imports/api/presentations';
|
2016-10-21 19:41:17 +08:00
|
|
|
import Slides from '/imports/api/slides';
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
|
|
|
import { isAllowedTo } from '/imports/startup/server/userPermissions';
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (!isAllowedTo('switchSlide', credentials)) {
|
2017-06-03 03:25:02 +08:00
|
|
|
throw new Meteor.Error('not-allowed', 'You are not allowed to switchSlide');
|
2016-10-21 19:41:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const Presentation = Presentations.findOne({
|
|
|
|
meetingId,
|
|
|
|
'presentation.current': true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!Presentation) {
|
2016-12-21 02:06:01 +08:00
|
|
|
throw new Meteor.Error(
|
2017-06-03 03:25:02 +08:00
|
|
|
'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,
|
|
|
|
presentationId: Presentation.presentation.id,
|
|
|
|
'slide.num': parseInt(slideNumber),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!Slide) {
|
2016-12-21 02:06:01 +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 = {
|
2016-10-21 19:41:17 +08:00
|
|
|
page: Slide.slide.id,
|
|
|
|
meeting_id: meetingId,
|
|
|
|
};
|
|
|
|
|
|
|
|
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|