Refactor handlers inside /phone to the /user folder

This commit is contained in:
Oswaldo Acauan 2017-02-23 18:52:50 +00:00
parent 99cfdb2062
commit d07bca00c9
3 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function handleListeningOnly({ payload }) {
const meetingId = payload.meeting_id;
const userId = payload.userid;
const listenOnly = payload.listen_only;
check(meetingId, String);
check(userId, String);
check(listenOnly, String);
const selector = {
meetingId,
userId,
};
const modifier = {
$set: {
'user.listenOnly': listenOnly,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Assigning user listen only status: ${err}`);
}
if (numChanged) {
return Logger.info(`Assigned listen only status '${listenOnly}' user=${userId} meeting=${meetingId}`);
}
};
return Users.update(selector, modifier, cb);
};

View File

@ -0,0 +1,20 @@
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import updateVoiceUser from '../modifiers/updateVoiceUser';
export default function handleVoiceUpdate({ payload }) {
const meetingId = payload.meeting_id;
const user = payload.user;
check(meetingId, String);
check(user, Object);
const voiceUser = user.voiceUser;
check(voiceUser, Object);
const userId = voiceUser.web_userid;
check(userId, Object);
return updateVoiceUser(meetingId, userId, voiceUser);
};

View File

@ -0,0 +1,24 @@
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/users';
export default function lockAllViewersMic(meetingId) {
const selector = {
meetingId,
'user.role': 'VIEWER',
'user.listenOnly': false,
'user.locked': true,
'user.voiceUser.joined': true,
'user.voiceUser.muted': false,
};
const usersToMute = Users.find(selector).fetch();
usersToMute.forEach(user =>
muteToggle({
meetingId,
requesterUserId: user.userId,
}, userId, true)
);
};