bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/methods/userLeaving.js
2019-07-01 16:00:27 -03:00

44 lines
1.3 KiB
JavaScript
Executable File

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 setConnectionStatus from '/imports/api/users/server/modifiers/setConnectionStatus';
export default function userLeaving(credentials, userId, connectionId) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
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) {
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;
}
const payload = {
userId,
sessionId: meetingId,
};
Logger.info(`User '${userId}' is leaving meeting '${meetingId}'`);
setConnectionStatus(meetingId, userId, 'offline');
return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
}