bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/handlers/presenterAssigned.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

import Users from '/imports/api/users';
import PresentationPods from '/imports/api/presentation-pods';
import changePresenter from '/imports/api/users/server/modifiers/changePresenter';
import RedisPubSub from '/imports/startup/server/redis';
function setPresenterInPodReqMsg(credentials) { // TODO-- switch to meetingId, etc
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'SetPresenterInPodReqMsg';
const { meetingId, requesterUserId, presenterId } = credentials;
const payload = {
podId: 'DEFAULT_PRESENTATION_POD',
nextPresenterId: presenterId,
};
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
}
2017-10-12 09:02:23 +08:00
export default async function handlePresenterAssigned({ body }, meetingId) {
2017-10-26 01:29:03 +08:00
const { presenterId, assignedBy } = body;
2017-10-12 09:02:23 +08:00
await changePresenter(true, presenterId, meetingId, assignedBy);
2017-02-23 02:59:47 +08:00
const selector = {
meetingId,
2017-10-26 01:29:03 +08:00
userId: { $ne: presenterId },
presenter: true,
2017-02-23 02:59:47 +08:00
};
const defaultPodSelector = {
meetingId,
podId: 'DEFAULT_PRESENTATION_POD',
};
const currentDefaultPod = await PresentationPods.findOneAsync(defaultPodSelector);
const setPresenterPayload = {
meetingId,
requesterUserId: assignedBy,
presenterId,
};
const prevPresenter = await Users.findOneAsync(selector);
if (prevPresenter) {
await changePresenter(false, prevPresenter.userId, meetingId, assignedBy);
}
/**
* In the cases where the first moderator joins the meeting or
* the current presenter left the meeting, akka-apps doesn't assign the new presenter
* to the default presentation pod. This step is done manually here.
*/
if (currentDefaultPod.currentPresenterId !== presenterId) {
const presenterToBeAssigned = await Users.findOneAsync({ userId: presenterId });
if (!presenterToBeAssigned) setPresenterPayload.presenterId = '';
setPresenterInPodReqMsg(setPresenterPayload);
}
2017-10-12 09:02:23 +08:00
}