2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2018-12-12 20:28:08 +08:00
|
|
|
import PresentationPods from '/imports/api/presentation-pods';
|
2019-06-29 04:52:19 +08:00
|
|
|
import changePresenter from '/imports/api/users/server/modifiers/changePresenter';
|
2020-04-29 20:00:32 +08:00
|
|
|
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
|
|
|
|
2023-04-01 04:40:41 +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
|
|
|
|
2023-04-01 04:40:41 +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
|
|
|
};
|
|
|
|
|
2021-07-24 02:50:51 +08:00
|
|
|
const defaultPodSelector = {
|
|
|
|
meetingId,
|
|
|
|
podId: 'DEFAULT_PRESENTATION_POD',
|
|
|
|
};
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
const currentDefaultPod = await PresentationPods.findOneAsync(defaultPodSelector);
|
2021-07-24 02:50:51 +08:00
|
|
|
|
2021-08-04 22:02:10 +08:00
|
|
|
const setPresenterPayload = {
|
|
|
|
meetingId,
|
|
|
|
requesterUserId: assignedBy,
|
|
|
|
presenterId,
|
|
|
|
};
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
const prevPresenter = await Users.findOneAsync(selector);
|
2018-12-12 20:28:08 +08:00
|
|
|
|
2021-09-30 00:21:07 +08:00
|
|
|
if (prevPresenter) {
|
2023-04-01 04:40:41 +08:00
|
|
|
await changePresenter(false, prevPresenter.userId, meetingId, assignedBy);
|
2021-09-30 00:21:07 +08:00
|
|
|
}
|
2018-12-12 20:28:08 +08:00
|
|
|
|
2021-09-30 00:21:07 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-12-12 20:28:08 +08:00
|
|
|
|
2021-09-30 00:21:07 +08:00
|
|
|
if (currentDefaultPod.currentPresenterId !== presenterId) {
|
2023-04-01 04:40:41 +08:00
|
|
|
const presenterToBeAssigned = await Users.findOneAsync({ userId: presenterId });
|
2018-12-12 20:28:08 +08:00
|
|
|
|
2021-09-30 00:21:07 +08:00
|
|
|
if (!presenterToBeAssigned) setPresenterPayload.presenterId = '';
|
2018-02-08 07:10:15 +08:00
|
|
|
|
2021-08-04 22:02:10 +08:00
|
|
|
setPresenterInPodReqMsg(setPresenterPayload);
|
|
|
|
}
|
2017-10-12 09:02:23 +08:00
|
|
|
}
|