bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/removeUser.js
Oswaldo Acauan 04b98036e7 Sends a ejectUserFromVoice after removing a user
Fix wrong linter change
2018-04-02 11:42:13 -03:00

52 lines
1.2 KiB
JavaScript

import { check } from 'meteor/check';
import Users from '/imports/api/users';
import Logger from '/imports/startup/server/logger';
import ejectUserFromVoice from '/imports/api/voice-users/server/methods/ejectUserFromVoice';
const CLIENT_TYPE_HTML = 'HTML5';
const clearAllSessions = (sessionUserId) => {
const serverSessions = Meteor.server.sessions;
Object.keys(serverSessions)
.filter(i => serverSessions[i].userId === sessionUserId)
.forEach(i => serverSessions[i].close());
};
export default function removeUser(meetingId, userId) {
check(meetingId, String);
check(userId, String);
const selector = {
meetingId,
userId,
};
const modifier = {
$set: {
connectionStatus: 'offline',
validated: false,
emoji: 'none',
presenter: false,
role: 'VIEWER',
},
};
const cb = (err) => {
if (err) {
return Logger.error(`Removing user from collection: ${err}`);
}
const sessionUserId = `${meetingId}-${userId}`;
clearAllSessions(sessionUserId);
ejectUserFromVoice({
requesterUserId: userId,
meetingId,
}, userId);
return Logger.info(`Removed ${CLIENT_TYPE_HTML} user id=${userId} meeting=${meetingId}`);
};
return Users.update(selector, modifier, cb);
}