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';
|
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';
|
2022-02-02 21:53:23 +08:00
|
|
|
import UsersPersistentData from '/imports/api/users-persistent-data';
|
2022-04-02 04:30:39 +08:00
|
|
|
import userEjected from '/imports/api/users/server/modifiers/userEjected';
|
2022-07-20 01:31:19 +08:00
|
|
|
import clearVoiceUser from '/imports/api/voice-users/server/modifiers/clearVoiceUser';
|
2017-02-23 02:59:47 +08:00
|
|
|
|
2022-03-30 03:08:34 +08:00
|
|
|
const disconnectUser = (meetingId, userId) => {
|
|
|
|
const sessionUserId = `${meetingId}--${userId}`;
|
|
|
|
ClientConnections.removeClientConnection(sessionUserId);
|
|
|
|
|
2018-02-20 23:02:04 +08:00
|
|
|
const serverSessions = Meteor.server.sessions;
|
2021-12-11 02:38:55 +08:00
|
|
|
const interable = serverSessions.values();
|
|
|
|
|
|
|
|
for (const session of interable) {
|
|
|
|
if (session.userId === sessionUserId) {
|
2022-03-30 03:08:34 +08:00
|
|
|
Logger.info(`Removed session id=${userId} meeting=${meetingId}`);
|
2021-12-11 02:38:55 +08:00
|
|
|
session.close();
|
|
|
|
}
|
|
|
|
}
|
2018-02-20 23:02:04 +08:00
|
|
|
};
|
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
export default async function removeUser(body, meetingId) {
|
2022-02-16 22:12:42 +08:00
|
|
|
const { intId: userId, reasonCode } = body;
|
2017-02-23 02:59:47 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
try {
|
2022-03-30 03:08:34 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
2021-12-11 02:38:55 +08:00
|
|
|
// 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')) {
|
2022-02-16 22:12:42 +08:00
|
|
|
if (body.eject) {
|
2023-03-15 21:18:31 +08:00
|
|
|
await userEjected(meetingId, userId, reasonCode);
|
2022-02-16 22:12:42 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
await setloggedOutStatus(userId, meetingId, true);
|
|
|
|
await VideoStreams.removeAsync({ meetingId, userId });
|
2019-02-19 20:14:29 +08:00
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
await clearUserInfoForRequester(meetingId, userId);
|
2017-02-23 02:59:47 +08:00
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
const currentUser = await UsersPersistentData.findOneAsync({ userId, meetingId });
|
2023-03-20 21:21:34 +08:00
|
|
|
const hasMessages = currentUser?.shouldPersist?.hasMessages?.public ||
|
|
|
|
currentUser?.shouldPersist?.hasMessages?.private;
|
2022-02-02 21:53:23 +08:00
|
|
|
const hasConnectionStatus = currentUser?.shouldPersist?.hasConnectionStatus;
|
|
|
|
|
|
|
|
if (!hasMessages && !hasConnectionStatus) {
|
2023-03-15 21:18:31 +08:00
|
|
|
await UsersPersistentData.removeAsync(selector);
|
2022-02-02 21:53:23 +08:00
|
|
|
}
|
2022-07-20 01:31:19 +08:00
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
await Users.removeAsync(selector);
|
|
|
|
await clearVoiceUser(meetingId, userId);
|
2019-02-19 20:14:29 +08:00
|
|
|
}
|
|
|
|
|
2021-12-11 02:38:55 +08:00
|
|
|
if (!process.env.BBB_HTML5_ROLE || process.env.BBB_HTML5_ROLE === 'frontend') {
|
2022-04-02 04:11:28 +08:00
|
|
|
// Wait for user removal and then kill user connections and sessions
|
2022-03-30 03:08:34 +08:00
|
|
|
const queryCurrentUser = Users.find(selector);
|
2023-03-15 21:18:31 +08:00
|
|
|
const countUser = await queryCurrentUser.countAsync();
|
|
|
|
if (countUser === 0) {
|
2022-03-30 03:08:34 +08:00
|
|
|
disconnectUser(meetingId, userId);
|
|
|
|
} else {
|
2022-04-02 04:11:28 +08:00
|
|
|
const queryUserObserver = queryCurrentUser.observeChanges({
|
2022-03-30 03:08:34 +08:00
|
|
|
removed() {
|
|
|
|
disconnectUser(meetingId, userId);
|
|
|
|
queryUserObserver.stop();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-12-11 03:13:26 +08:00
|
|
|
}
|
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
|
|
|
}
|