2017-09-07 03:36:52 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2017-09-07 03:36:52 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2019-07-04 02:10:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-09-07 03:36:52 +08:00
|
|
|
|
|
|
|
export default function endMeeting(credentials) {
|
2018-01-08 08:24:05 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
2017-09-07 03:36:52 +08:00
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'LogoutAndEndMeetingCmdMsg';
|
2019-07-04 02:10:28 +08:00
|
|
|
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
|
2017-09-07 03:36:52 +08:00
|
|
|
|
|
|
|
const { meetingId, requesterUserId, requesterToken } = credentials;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(requesterToken, String);
|
|
|
|
|
2019-07-04 02:10:28 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2017-09-07 03:36:52 +08:00
|
|
|
userId: requesterUserId,
|
|
|
|
};
|
2019-07-04 02:10:28 +08:00
|
|
|
const user = Users.findOne(selector);
|
2017-09-07 03:36:52 +08:00
|
|
|
|
2019-07-05 03:25:25 +08:00
|
|
|
if (!!user && user.role === ROLE_MODERATOR) {
|
2019-07-04 02:10:28 +08:00
|
|
|
const payload = {
|
|
|
|
userId: requesterUserId,
|
|
|
|
};
|
2017-09-07 03:36:52 +08:00
|
|
|
|
2019-07-04 02:10:28 +08:00
|
|
|
Logger.verbose(`Meeting '${meetingId}' is destroyed by '${requesterUserId}'`);
|
|
|
|
|
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
|
|
|
|
}
|
2017-09-07 03:36:52 +08:00
|
|
|
}
|