Merge pull request #14690 from gustavotrott/fix-user-ejected-reconnecting

fix: Rejected user keep trying to reconnect
This commit is contained in:
Anton Georgiev 2022-03-29 16:10:51 -04:00 committed by GitHub
commit 2c90124869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,12 +8,16 @@ import ClientConnections from '/imports/startup/server/ClientConnections';
import UsersPersistentData from '/imports/api/users-persistent-data';
import VoiceUsers from '/imports/api/voice-users/';
const clearAllSessions = (sessionUserId) => {
const disconnectUser = (meetingId, userId) => {
const sessionUserId = `${meetingId}--${userId}`;
ClientConnections.removeClientConnection(sessionUserId);
const serverSessions = Meteor.server.sessions;
const interable = serverSessions.values();
for (const session of interable) {
if (session.userId === sessionUserId) {
Logger.info(`Removed session id=${userId} meeting=${meetingId}`);
session.close();
}
}
@ -24,14 +28,14 @@ export default function removeUser(meetingId, userId) {
check(userId, String);
try {
const selector = {
meetingId,
userId,
};
// 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 });
@ -49,9 +53,19 @@ export default function removeUser(meetingId, userId) {
}
if (!process.env.BBB_HTML5_ROLE || process.env.BBB_HTML5_ROLE === 'frontend') {
const sessionUserId = `${meetingId}--${userId}`;
ClientConnections.removeClientConnection(sessionUserId);
clearAllSessions(sessionUserId);
//Wait for user removal and then kill user connections and sessions
const queryCurrentUser = Users.find(selector);
if (queryCurrentUser.count() === 0) {
disconnectUser(meetingId, userId);
} else {
let queryUserObserver = queryCurrentUser.observeChanges({
removed() {
disconnectUser(meetingId, userId);
queryUserObserver.stop();
},
});
}
}
Logger.info(`Removed user id=${userId} meeting=${meetingId}`);