2017-08-01 03:36:41 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
|
2017-12-08 04:50:50 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import Users from '/imports/api/users';
|
2017-08-01 03:36:41 +08:00
|
|
|
import addVoiceUser from '../modifiers/addVoiceUser';
|
|
|
|
|
|
|
|
export default function handleJoinVoiceUser({ body }, meetingId) {
|
|
|
|
const voiceUser = body;
|
2017-08-02 21:11:53 +08:00
|
|
|
voiceUser.joined = true;
|
2017-08-01 03:36:41 +08:00
|
|
|
|
|
|
|
check(meetingId, String);
|
2017-12-08 04:50:50 +08:00
|
|
|
check(voiceUser, {
|
|
|
|
voiceConf: String,
|
|
|
|
intId: String,
|
|
|
|
voiceUserId: String,
|
|
|
|
callerName: String,
|
|
|
|
callerNum: String,
|
|
|
|
muted: Boolean,
|
|
|
|
talking: Boolean,
|
|
|
|
callingWith: String,
|
|
|
|
listenOnly: Boolean,
|
|
|
|
joined: Boolean,
|
|
|
|
});
|
|
|
|
|
|
|
|
const {
|
|
|
|
intId,
|
|
|
|
callerName,
|
|
|
|
} = voiceUser;
|
|
|
|
|
|
|
|
if (intId.toString().startsWith('v_')) {
|
|
|
|
/* voice-only user - called into the conference */
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId: intId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const USER_CONFIG = Meteor.settings.public.user;
|
|
|
|
const ROLE_VIEWER = USER_CONFIG.role_viewer;
|
|
|
|
|
2018-06-27 04:50:03 +08:00
|
|
|
const modifier = { // web (Users) representation of dial-in user
|
2017-12-08 04:50:50 +08:00
|
|
|
$set: {
|
|
|
|
meetingId,
|
|
|
|
connectionStatus: 'online',
|
|
|
|
roles: [ROLE_VIEWER.toLowerCase()],
|
|
|
|
sortName: callerName.trim().toLowerCase(),
|
|
|
|
color: '#ffffff', // TODO
|
|
|
|
intId,
|
|
|
|
extId: intId, // TODO
|
|
|
|
name: callerName,
|
|
|
|
role: ROLE_VIEWER.toLowerCase(),
|
|
|
|
guest: false,
|
|
|
|
authed: true,
|
|
|
|
waitingForAcceptance: false,
|
|
|
|
emoji: 'none',
|
|
|
|
presenter: false,
|
|
|
|
locked: false, // TODO
|
|
|
|
avatar: '',
|
2018-06-27 04:50:03 +08:00
|
|
|
clientType: 'dial-in-user',
|
2017-12-08 04:50:50 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Adding call-in user to VoiceUser collection: ${err}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { insertedId } = numChanged;
|
|
|
|
if (insertedId) {
|
|
|
|
return Logger.info(`Added a call-in user id=${intId} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Logger.info(`Upserted a call-in user id=${intId} meeting=${meetingId}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
Users.upsert(selector, modifier, cb);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* there is a corresponding web user in Users collection -- no need to add new one */
|
|
|
|
}
|
2017-08-01 03:36:41 +08:00
|
|
|
|
|
|
|
return addVoiceUser(meetingId, voiceUser);
|
|
|
|
}
|