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

53 lines
1.7 KiB
JavaScript
Raw Normal View History

import Users from '/imports/api/users';
import PresentationPods from '/imports/api/presentation-pods';
2017-10-26 01:29:03 +08:00
import changeRole from '/imports/api/users/server/modifiers/changeRole';
import setPresenterInPodReqMsg from '/imports/api/presentation-pods/server/methods/setPresenterInPodReqMsg';
2017-10-12 09:02:23 +08:00
2018-12-07 03:07:51 +08:00
export default function handlePresenterAssigned({ body }, meetingId) {
2017-10-26 03:00:31 +08:00
const USER_CONFIG = Meteor.settings.public.user;
const ROLE_PRESENTER = USER_CONFIG.role_presenter;
2017-10-26 01:29:03 +08:00
const { presenterId, assignedBy } = body;
2017-10-12 09:02:23 +08:00
2017-10-26 03:00:31 +08:00
changeRole(ROLE_PRESENTER, 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
};
2017-10-26 01:29:03 +08:00
const prevPresenter = Users.findOne(selector);
// no previous presenters
// The below code is responsible for set Meeting presenter to be default pod presenter as well.
// It's been handled here because right now akka-apps don't handle all cases scenarios.
if (!prevPresenter) {
const setPresenterPayload = {
meetingId,
requesterUserId: assignedBy,
presenterId,
};
const defaultPodSelector = {
podId: 'DEFAULT_PRESENTATION_POD',
};
const currentDefaultPodPresenter = PresentationPods.findOne(defaultPodSelector);
const { currentPresenterId } = currentDefaultPodPresenter;
if (currentPresenterId === '') {
return setPresenterInPodReqMsg(setPresenterPayload);
}
const oldPresenter = Users.findOne({ userId: currentPresenterId, connectionStatus: 'offline' });
if (oldPresenter) {
return setPresenterInPodReqMsg(setPresenterPayload);
}
2018-12-01 03:34:00 +08:00
return true;
}
return changeRole(ROLE_PRESENTER, false, prevPresenter.userId, meetingId, assignedBy);
2017-10-12 09:02:23 +08:00
}