2017-10-12 10:00:28 +08:00
|
|
|
import Presentations from '/imports/api/presentations';
|
2019-08-01 03:10:41 +08:00
|
|
|
import { Slides } from '/imports/api/slides';
|
2016-10-21 19:41:17 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2020-02-07 04:47:28 +08:00
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
2016-10-21 19:41:17 +08:00
|
|
|
|
2020-02-07 04:47:28 +08:00
|
|
|
export default function switchSlide(slideNumber, podId) { // TODO-- send presentationId and SlideId
|
2018-01-08 08:24:05 +08:00
|
|
|
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';
|
2020-02-07 04:47:28 +08:00
|
|
|
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,
|
2018-04-12 04:05:30 +08:00
|
|
|
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,
|
2018-04-12 04:05:30 +08:00
|
|
|
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 = {
|
2018-04-12 04:05:30 +08:00
|
|
|
podId,
|
2017-10-12 08:59:35 +08:00
|
|
|
presentationId: Presentation.id,
|
2018-04-12 04:05:30 +08:00
|
|
|
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
|
|
|
}
|