bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/changePresenter.js

38 lines
1.1 KiB
JavaScript
Raw Normal View History

import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
import Meetings from '/imports/api/meetings';
import stopWatchingExternalVideo from '/imports/api/external-videos/server/methods/stopWatchingExternalVideo';
export default function changePresenter(presenter, userId, meetingId, changedBy) {
const selector = {
meetingId,
userId,
};
const modifier = {
$set: {
presenter,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Changed user role: ${err}`);
}
if (numChanged) {
return Logger.info(`Changed presenter=${presenter} id=${userId} meeting=${meetingId}`
+ `${changedBy ? ` changedBy=${changedBy}` : ''}`);
}
return null;
};
const meeting = Meetings.findOne({ meetingId });
if (meeting && meeting.externalVideoUrl) {
Logger.info(`ChangePresenter:There is external video being shared. Stopping it due to presenter change, ${meeting.externalVideoUrl}`);
stopWatchingExternalVideo({ meetingId, requesterUserId: userId });
}
return Users.update(selector, modifier, cb);
}