2019-06-29 04:52:19 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import Users from '/imports/api/users';
|
2019-12-19 05:40:04 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
|
|
|
import stopWatchingExternalVideo from '/imports/api/external-videos/server/methods/stopWatchingExternalVideo';
|
2019-06-29 04:52:19 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2019-12-19 05:40:04 +08:00
|
|
|
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 });
|
|
|
|
}
|
2019-06-29 04:52:19 +08:00
|
|
|
return Users.update(selector, modifier, cb);
|
|
|
|
}
|