diff --git a/bigbluebutton-html5/imports/api/users/server/modifiers/removeUser.js b/bigbluebutton-html5/imports/api/users/server/modifiers/removeUser.js
index d9bdc8109d..adedf6d338 100755
--- a/bigbluebutton-html5/imports/api/users/server/modifiers/removeUser.js
+++ b/bigbluebutton-html5/imports/api/users/server/modifiers/removeUser.js
@@ -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}`);