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

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-02-07 23:29:27 +08:00
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
2019-07-02 03:00:27 +08:00
import setConnectionStatus from '/imports/api/users/server/modifiers/setConnectionStatus';
export default function userLeaving(credentials, userId, connectionId) {
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';
const { meetingId, requesterUserId } = credentials;
check(meetingId, String);
check(requesterUserId, String);
check(userId, String);
2017-03-11 02:33:46 +08:00
const selector = {
meetingId,
userId,
2017-03-11 02:33:46 +08:00
};
const User = Users.findOne(selector);
if (!User) {
2018-06-19 23:38:53 +08:00
return Logger.info(`Skipping userLeaving. Could not find ${userId} in ${meetingId}`);
}
// If the current user connection is not the same that triggered the leave we skip
if (User.connectionId !== connectionId) {
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,
};
Logger.info(`User '${userId}' is leaving meeting '${meetingId}'`);
2019-07-02 03:00:27 +08:00
setConnectionStatus(meetingId, userId, 'offline');
2017-10-12 09:02:23 +08:00
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
2017-06-03 03:25:02 +08:00
}