2017-02-07 23:29:27 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-02-07 21:08:06 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import RedisPubSub from '/imports/startup/server/redis';
|
2017-02-07 21:08:06 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-09-10 19:49:22 +08:00
|
|
|
import AuthTokenValidation from '/imports/api/auth-token-validation';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-02-07 21:08:06 +08:00
|
|
|
|
2020-02-14 03:19:29 +08:00
|
|
|
export default function userLeaving(meetingId, userId, connectionId) {
|
2018-01-08 08:24:05 +08:00
|
|
|
const REDIS_CONFIG = Meteor.settings.private.redis;
|
2017-10-12 09:02:23 +08:00
|
|
|
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
|
|
|
|
const EVENT_NAME = 'UserLeaveReqMsg';
|
2017-02-07 21:08:06 +08:00
|
|
|
|
|
|
|
check(userId, String);
|
|
|
|
|
2017-03-11 02:33:46 +08:00
|
|
|
const selector = {
|
2017-02-07 21:08:06 +08:00
|
|
|
meetingId,
|
2017-02-24 04:16:10 +08:00
|
|
|
userId,
|
2017-03-11 02:33:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const User = Users.findOne(selector);
|
2018-02-20 22:21:51 +08:00
|
|
|
|
2017-02-07 21:08:06 +08:00
|
|
|
if (!User) {
|
2018-06-19 23:38:53 +08:00
|
|
|
return Logger.info(`Skipping userLeaving. Could not find ${userId} in ${meetingId}`);
|
2017-02-07 21:08:06 +08:00
|
|
|
}
|
|
|
|
|
2020-09-10 19:49:22 +08:00
|
|
|
const auth = AuthTokenValidation.findOne({
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
connectionId,
|
|
|
|
});
|
|
|
|
|
2018-02-20 22:21:51 +08:00
|
|
|
// If the current user connection is not the same that triggered the leave we skip
|
2020-09-10 19:49:22 +08:00
|
|
|
if (User.connectionId !== connectionId && !auth) {
|
2018-02-20 22:21:51 +08:00
|
|
|
return false;
|
2017-03-11 02:33:46 +08:00
|
|
|
}
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const payload = {
|
2017-10-12 09:02:23 +08:00
|
|
|
userId,
|
|
|
|
sessionId: meetingId,
|
2017-02-07 21:08:06 +08:00
|
|
|
};
|
2017-04-18 01:20:09 +08:00
|
|
|
|
2018-02-20 22:21:51 +08:00
|
|
|
Logger.info(`User '${userId}' is leaving meeting '${meetingId}'`);
|
2020-02-14 03:19:29 +08:00
|
|
|
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, userId, payload);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|