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

41 lines
1.2 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';
import ClientConnections from '/imports/startup/server/ClientConnections';
export default function userLeaving(meetingId, 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';
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,
};
ClientConnections.removeClientConnection(`${meetingId}--${userId}`, connectionId);
Logger.info(`User '${userId}' is leaving meeting '${meetingId}'`);
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, userId, payload);
2017-06-03 03:25:02 +08:00
}