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';
|
2021-05-06 00:17:26 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2016-10-21 19:41:17 +08:00
|
|
|
|
2023-03-16 01:35:25 +08:00
|
|
|
export default async function switchSlide(slideNumber, podId) {
|
|
|
|
// TODO-- send presentationId and SlideId
|
2018-01-08 08:24:05 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
2017-10-12 08:59:35 +08:00
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'SetCurrentPagePubMsg';
|
|
|
|
|
2021-05-06 00:17:26 +08:00
|
|
|
try {
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(slideNumber, Number);
|
|
|
|
check(podId, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
current: true,
|
|
|
|
};
|
|
|
|
|
2023-03-16 01:35:25 +08:00
|
|
|
const Presentation = await Presentations.findOneAsync(selector);
|
2021-05-06 00:17:26 +08:00
|
|
|
|
|
|
|
if (!Presentation) {
|
|
|
|
throw new Meteor.Error('presentation-not-found', 'You need a presentation to be able to switch slides');
|
|
|
|
}
|
|
|
|
|
2023-03-16 01:35:25 +08:00
|
|
|
const Slide = await Slides.findOneAsync({
|
2021-05-06 00:17:26 +08:00
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
presentationId: Presentation.id,
|
|
|
|
num: slideNumber,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!Slide) {
|
|
|
|
throw new Meteor.Error('slide-not-found', `Slide number ${slideNumber} not found in the current presentation`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
podId,
|
|
|
|
presentationId: Presentation.id,
|
|
|
|
pageId: Slide.id,
|
|
|
|
};
|
|
|
|
|
|
|
|
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method switchSlide ${err.stack}`);
|
2016-10-21 19:41:17 +08:00
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|