bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/removeUser.js

55 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-02-23 02:59:47 +08:00
import { check } from 'meteor/check';
import Users from '/imports/api/users';
2019-09-07 00:50:31 +08:00
import VideoStreams from '/imports/api/video-streams';
2017-02-23 02:59:47 +08:00
import Logger from '/imports/startup/server/logger';
import setloggedOutStatus from '/imports/api/users-persistent-data/server/modifiers/setloggedOutStatus';
import clearUserInfoForRequester from '/imports/api/users-infos/server/modifiers/clearUserInfoForRequester';
import ClientConnections from '/imports/startup/server/ClientConnections';
2021-12-11 03:13:26 +08:00
import VoiceUsers from '/imports/api/voice-users/';
2017-02-23 02:59:47 +08:00
const clearAllSessions = (sessionUserId) => {
const serverSessions = Meteor.server.sessions;
const interable = serverSessions.values();
for (const session of interable) {
if (session.userId === sessionUserId) {
session.close();
}
}
};
2017-02-23 02:59:47 +08:00
export default function removeUser(meetingId, userId) {
check(meetingId, String);
check(userId, String);
try {
// we don't want to fully process the redis message in frontend
// since the backend is supposed to update Mongo
if ((process.env.BBB_HTML5_ROLE !== 'frontend')) {
const selector = {
meetingId,
userId,
};
setloggedOutStatus(userId, meetingId, true);
VideoStreams.remove({ meetingId, userId });
clearUserInfoForRequester(meetingId, userId);
2017-02-23 02:59:47 +08:00
Users.remove(selector);
VoiceUsers.remove({ intId: userId, meetingId });
}
if (!process.env.BBB_HTML5_ROLE || process.env.BBB_HTML5_ROLE === 'frontend') {
const sessionUserId = `${meetingId}--${userId}`;
ClientConnections.removeClientConnection(sessionUserId);
clearAllSessions(sessionUserId);
2021-12-11 03:13:26 +08:00
}
Logger.info(`Removed user id=${userId} meeting=${meetingId}`);
} catch (err) {
Logger.error(`Removing user from Users collection: ${err}`);
}
2017-06-03 03:25:02 +08:00
}