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';
|
2017-02-23 02:59:47 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2019-02-19 20:14:29 +08:00
|
|
|
import stopWatchingExternalVideo from '/imports/api/external-videos/server/methods/stopWatchingExternalVideo';
|
2017-02-23 02:59:47 +08:00
|
|
|
|
2018-02-20 23:02:04 +08:00
|
|
|
const clearAllSessions = (sessionUserId) => {
|
|
|
|
const serverSessions = Meteor.server.sessions;
|
|
|
|
Object.keys(serverSessions)
|
|
|
|
.filter(i => serverSessions[i].userId === sessionUserId)
|
|
|
|
.forEach(i => serverSessions[i].close());
|
|
|
|
};
|
|
|
|
|
2017-02-23 02:59:47 +08:00
|
|
|
export default function removeUser(meetingId, userId) {
|
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
|
|
|
|
2019-02-19 20:14:29 +08:00
|
|
|
const userToRemove = Users.findOne({ userId });
|
|
|
|
|
|
|
|
if (userToRemove) {
|
|
|
|
const { presenter } = userToRemove;
|
|
|
|
if (presenter) {
|
|
|
|
stopWatchingExternalVideo({ meetingId, requesterUserId: userId });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-23 02:59:47 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
2017-10-12 09:02:23 +08:00
|
|
|
connectionStatus: 'offline',
|
|
|
|
validated: false,
|
|
|
|
emoji: 'none',
|
|
|
|
presenter: false,
|
|
|
|
role: 'VIEWER',
|
2017-02-23 02:59:47 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-10-12 09:02:23 +08:00
|
|
|
const cb = (err) => {
|
2017-02-23 02:59:47 +08:00
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Removing user from collection: ${err}`);
|
|
|
|
}
|
|
|
|
|
2018-02-20 23:02:04 +08:00
|
|
|
const sessionUserId = `${meetingId}-${userId}`;
|
|
|
|
clearAllSessions(sessionUserId);
|
|
|
|
|
2018-06-23 03:19:46 +08:00
|
|
|
return Logger.info(`Removed user id=${userId} meeting=${meetingId}`);
|
2017-02-23 02:59:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Users.update(selector, modifier, cb);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|