Handle CreateNewPresentationPod message

This commit is contained in:
Oleksandr Zhurbenko 2018-04-05 12:59:26 -07:00
parent eef2d65d93
commit e5a4bd09b4
6 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import { Meteor } from 'meteor/meteor';
const PresentationPods = new Mongo.Collection('presentation-pods');
if (Meteor.isServer) {
// types of queries for the presentation pods:
// 1. meetingId, podId
// 2. meetingId
PresentationPods._ensureIndex({ meetingId: 1, podId: 1 });
}
export default PresentationPods;

View File

@ -0,0 +1,12 @@
import RedisPubSub from '/imports/startup/server/redis';
import handleCreateNewPresentationPod from './handlers/createNewPresentationPod';
import handleRemovePresentationPod from './handlers/removePresentationPod';
import handleGetAllPresentationPods from './handlers/getAllPresentationPods';
import handleSetPresenterInPod from './handlers/setPresenterInPod';
// import handleSyncGetPresentationPods from './handlers/syncGetPresentationPods';
RedisPubSub.on('CreateNewPresentationPodEvtMsg', handleCreateNewPresentationPod);
RedisPubSub.on('RemovePresentationPodEvtMsg', handleRemovePresentationPod);
// RedisPubSub.on('GetAllPresentationPodsRespMsg', handleGetAllPresentationPods);
RedisPubSub.on('SetPresenterInPodRespMsg', handleSetPresenterInPod);
RedisPubSub.on('SyncGetPresentationPodsRespMsg', handleGetAllPresentationPods);

View File

@ -0,0 +1,19 @@
import { check } from 'meteor/check';
import addPresentationPod from '../modifiers/addPresentationPod';
export default function handleCreateNewPresentationPod({ body }, meetingId) {
check(body, {
currentPresenterId: String,
podId: String,
});
check(meetingId, String);
const { currentPresenterId, podId } = body;
const pod = {
currentPresenterId,
podId,
};
addPresentationPod(meetingId, pod);
}

View File

@ -0,0 +1,3 @@
import './eventHandlers';
// import './methods';
import './publishers';

View File

@ -0,0 +1,39 @@
import { Match, check } from 'meteor/check';
import PresentationPods from '/imports/api/presentation-pods';
import Logger from '/imports/startup/server/logger';
export default function addPresentationPod(meetingId, pod, presentation = null /* ?? */) {
check(meetingId, String);
check(presentation, Match.Maybe(Object));
check(pod, {
currentPresenterId: String,
podId: String,
});
const { currentPresenterId, podId } = pod;
const selector = {
meetingId,
podId,
};
const modifier = {
meetingId,
podId,
currentPresenterId,
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding presentation pod to the collection: ${err}`);
}
if (numChanged) {
return Logger.info(`Added presentation pod id=${podId} meeting=${meetingId}`);
}
return Logger.info(`Upserted presentation pod id=${podId} meeting=${meetingId}`);
};
return PresentationPods.upsert(selector, modifier, cb);
}

View File

@ -0,0 +1,24 @@
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import PresentationPods from '/imports/api/presentations';
import Logger from '/imports/startup/server/logger';
import mapToAcl from '/imports/startup/mapToAcl';
function presentationPods(credentials) {
const { meetingId, requesterUserId, requesterToken } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(requesterToken, String);
Logger.info(`Publishing PresentationPods for ${meetingId} ${requesterUserId} ${requesterToken}`);
return PresentationPods.find({ meetingId });
}
function publish(...args) {
const boundPresentationPods = presentationPods.bind(this);
return mapToAcl('subscriptions.presentationPods', boundPresentationPods)(args);
}
Meteor.publish('presentationPods', publish);