2017-02-23 02:59:47 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2021-11-29 21:34:09 +08:00
|
|
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
2021-11-29 21:59:21 +08:00
|
|
|
import VoiceUsers from '/imports/api/voice-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';
|
2021-03-23 04:44:53 +08:00
|
|
|
import setloggedOutStatus from '/imports/api/users-persistent-data/server/modifiers/setloggedOutStatus';
|
2019-04-06 06:32:21 +08:00
|
|
|
import clearUserInfoForRequester from '/imports/api/users-infos/server/modifiers/clearUserInfoForRequester';
|
2020-09-01 20:07:56 +08:00
|
|
|
import ClientConnections from '/imports/startup/server/ClientConnections';
|
2017-02-23 02:59:47 +08:00
|
|
|
|
2018-02-20 23:02:04 +08:00
|
|
|
const clearAllSessions = (sessionUserId) => {
|
|
|
|
const serverSessions = Meteor.server.sessions;
|
2021-11-24 04:35:48 +08:00
|
|
|
const interable = serverSessions.values();
|
|
|
|
|
|
|
|
for (const session of interable) {
|
|
|
|
if (session.userId === sessionUserId) {
|
|
|
|
session.close();
|
|
|
|
}
|
|
|
|
}
|
2018-02-20 23:02:04 +08:00
|
|
|
};
|
|
|
|
|
2017-02-23 02:59:47 +08:00
|
|
|
export default function removeUser(meetingId, userId) {
|
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
try {
|
2021-07-01 04:08:00 +08:00
|
|
|
if (!process.env.BBB_HTML5_ROLE || process.env.BBB_HTML5_ROLE === 'frontend') {
|
2021-11-24 04:35:48 +08:00
|
|
|
const sessionUserId = `${meetingId}--${userId}`;
|
|
|
|
ClientConnections.removeClientConnection(sessionUserId);
|
2021-07-01 04:08:00 +08:00
|
|
|
clearAllSessions(sessionUserId);
|
|
|
|
|
|
|
|
// 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') {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-19 20:14:29 +08:00
|
|
|
}
|
|
|
|
|
2021-07-01 04:08:00 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
2017-02-23 02:59:47 +08:00
|
|
|
|
2021-03-23 04:44:53 +08:00
|
|
|
setloggedOutStatus(userId, meetingId, true);
|
2020-11-25 04:44:13 +08:00
|
|
|
VideoStreams.remove({ meetingId, userId });
|
2018-02-20 23:02:04 +08:00
|
|
|
|
2019-04-06 06:32:21 +08:00
|
|
|
clearUserInfoForRequester(meetingId, userId);
|
|
|
|
|
2021-11-29 21:34:09 +08:00
|
|
|
const currentUser = Users.findOne({ userId, meetingId });
|
|
|
|
const hasMessages = currentUser?.hasMessages;
|
|
|
|
|
|
|
|
if (!hasMessages) {
|
|
|
|
UsersPersistentData.remove(selector);
|
|
|
|
}
|
2021-07-01 04:08:00 +08:00
|
|
|
Users.remove(selector);
|
2021-11-29 21:59:21 +08:00
|
|
|
VoiceUsers.remove({ intId: userId, meetingId })
|
2020-12-02 04:02:50 +08:00
|
|
|
|
|
|
|
Logger.info(`Removed user id=${userId} meeting=${meetingId}`);
|
2020-11-25 04:44:13 +08:00
|
|
|
} catch (err) {
|
2020-12-02 04:02:50 +08:00
|
|
|
Logger.error(`Removing user from Users collection: ${err}`);
|
2020-11-25 04:44:13 +08:00
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|