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

66 lines
2.2 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 stopWatchingExternalVideoSystemCall from '/imports/api/external-videos/server/methods/stopWatchingExternalVideoSystemCall';
import clearUserInfoForRequester from '/imports/api/users-infos/server/modifiers/clearUserInfoForRequester';
import ClientConnections from '/imports/startup/server/ClientConnections';
2017-02-23 02:59:47 +08:00
const clearAllSessions = (sessionUserId) => {
const serverSessions = Meteor.server.sessions;
Object.keys(serverSessions)
2021-04-17 01:58:53 +08:00
.filter((i) => serverSessions[i].userId === sessionUserId)
.forEach((i) => serverSessions[i].close());
};
2017-02-23 02:59:47 +08:00
export default function removeUser(meetingId, userId) {
check(meetingId, String);
check(userId, String);
const userToRemove = Users.findOne({ userId, meetingId });
if (userToRemove) {
const { presenter } = userToRemove;
if (presenter) {
stopWatchingExternalVideoSystemCall({ meetingId, requesterUserId: 'system-presenter-was-removed' });
}
}
2017-02-23 02:59:47 +08:00
const selector = {
meetingId,
userId,
};
try {
setloggedOutStatus(userId, meetingId, true);
VideoStreams.remove({ meetingId, userId });
const sessionUserId = `${meetingId}-${userId}`;
ClientConnections.removeClientConnection(`${meetingId}--${userId}`);
clearAllSessions(sessionUserId);
clearUserInfoForRequester(meetingId, userId);
2021-04-17 03:32:16 +08:00
/*
Timeout added to reduce the probability that "userRemove" happens too close to "ejectUser",
redirecting user to the wrong component.
This is a workaround and should be removed as soon as a better fix is made
see: https://github.com/bigbluebutton/bigbluebutton/pull/12057
*/
const DELAY_USER_REMOVAL_TIMEOUT_MS = 1000;
2021-04-17 01:58:53 +08:00
Meteor.wrapAsync((callback) => {
Meteor.setTimeout(() => {
Users.remove(selector);
callback();
2021-04-17 03:32:16 +08:00
}, DELAY_USER_REMOVAL_TIMEOUT_MS);
2021-04-17 01:58:53 +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
}