bigbluebutton-Github/bigbluebutton-html5/imports/api/2.0/users/server/methods/userLeaving.js

62 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-06-19 21:13:35 +08:00
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis2x';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/2.0/users';
const OFFLINE_CONNECTION_STATUS = 'offline';
export default function userLeaving(credentials, userId) {
const REDIS_CONFIG = Meteor.settings.redis;
2017-07-15 00:59:02 +08:00
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
2017-06-19 21:13:35 +08:00
const EVENT_NAME = 'UserLeaveReqMsg';
const { meetingId, requesterUserId } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(userId, String);
const selector = {
meetingId,
userId,
};
const User = Users.findOne(selector);
if (!User) {
throw new Meteor.Error(
'user-not-found', `Could not find ${userId} in ${meetingId}: cannot complete userLeaving`);
}
2017-07-26 22:09:07 +08:00
if (User.connectionStatus === OFFLINE_CONNECTION_STATUS) {
2017-07-15 00:59:02 +08:00
return null;
2017-06-19 21:13:35 +08:00
}
if (User.validated) {
const modifier = {
$set: {
validated: null,
},
};
2017-07-15 00:59:02 +08:00
const cb = (err) => {
2017-06-19 21:13:35 +08:00
if (err) {
return Logger.error(`Invalidating user: ${err}`);
}
2017-07-15 00:59:02 +08:00
return Logger.info(`Invalidate user=${userId} meeting=${meetingId}`);
2017-06-19 21:13:35 +08:00
};
Users.update(selector, modifier, cb);
}
2017-07-15 00:59:02 +08:00
const payload = {
2017-07-13 21:15:42 +08:00
userId,
2017-07-15 00:59:02 +08:00
sessionId: meetingId,
2017-06-19 21:13:35 +08:00
};
Logger.verbose(`User '${requesterUserId}' left meeting '${meetingId}'`);
2017-07-15 00:59:02 +08:00
return RedisPubSub.buildMessageheader(CHANNEL, EVENT_NAME, meetingId, payload, requesterUserId);
2017-06-19 21:13:35 +08:00
}