2017-06-19 21:13:35 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-06-29 02:14:29 +08:00
|
|
|
import Users from '/imports/api/2.0/users';
|
2017-08-01 21:10:12 +08:00
|
|
|
import addVoiceUser from '/imports/api/2.0/voice-users/server/modifiers/addVoiceUser';
|
2017-06-19 21:13:35 +08:00
|
|
|
|
|
|
|
export default function addUser(meetingId, user) {
|
|
|
|
check(user, Object);
|
|
|
|
check(meetingId, String);
|
|
|
|
|
2017-06-22 00:54:04 +08:00
|
|
|
const userId = user.intId;
|
2017-06-19 21:13:35 +08:00
|
|
|
check(userId, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const USER_CONFIG = Meteor.settings.public.user;
|
|
|
|
const ROLE_MODERATOR = USER_CONFIG.role_moderator;
|
|
|
|
const ROLE_VIEWER = USER_CONFIG.role_viewer;
|
|
|
|
const APP_CONFIG = Meteor.settings.public.app;
|
|
|
|
const ALLOW_HTML5_MODERATOR = APP_CONFIG.allowHTML5Moderator;
|
|
|
|
|
|
|
|
// override moderator status of html5 client users, depending on a system flag
|
|
|
|
const dummyUser = Users.findOne(selector);
|
2017-06-28 06:14:53 +08:00
|
|
|
|
2017-06-19 21:13:35 +08:00
|
|
|
if (dummyUser &&
|
|
|
|
dummyUser.clientType === 'HTML5' &&
|
|
|
|
user.role === ROLE_MODERATOR &&
|
|
|
|
!ALLOW_HTML5_MODERATOR) {
|
|
|
|
user.role = ROLE_VIEWER;
|
|
|
|
}
|
|
|
|
|
2017-07-26 00:21:07 +08:00
|
|
|
let userRoles = [];
|
|
|
|
|
|
|
|
userRoles.push(
|
|
|
|
'viewer',
|
|
|
|
user.presenter ? 'presenter' : false,
|
|
|
|
user.role === 'MODERATOR' ? 'moderator' : false,
|
|
|
|
);
|
|
|
|
|
|
|
|
userRoles = userRoles.filter(Boolean);
|
2017-06-19 21:13:35 +08:00
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
'user.connection_status': 'online',
|
|
|
|
'user.userid': userId,
|
2017-06-22 00:54:04 +08:00
|
|
|
'user.extId': user.extId,
|
2017-06-19 21:13:35 +08:00
|
|
|
'user.role': user.role,
|
|
|
|
'user.roles': userRoles,
|
|
|
|
'user.name': user.name,
|
|
|
|
'user._sort_name': user.name.trim().toLowerCase(),
|
2017-06-22 00:54:04 +08:00
|
|
|
'user.avatarURL': user.avatar,
|
2017-06-19 21:13:35 +08:00
|
|
|
'user.set_emoji_time': user.set_emoji_time || (new Date()).getTime(),
|
2017-06-22 00:54:04 +08:00
|
|
|
'user.joiningTime': (new Date()).getTime(),
|
2017-07-13 21:15:42 +08:00
|
|
|
'user.emoji': user.emoji,
|
2017-06-19 21:13:35 +08:00
|
|
|
'user.presenter': user.presenter,
|
|
|
|
'user.locked': user.locked,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-08-01 21:10:12 +08:00
|
|
|
addVoiceUser(meetingId, {
|
|
|
|
voiceUserId: '',
|
|
|
|
intId: userId,
|
|
|
|
callerName: user.name,
|
|
|
|
callerNum: '',
|
|
|
|
muted: false,
|
|
|
|
talking: false,
|
|
|
|
callingWith: '',
|
|
|
|
listenOnly: false,
|
|
|
|
voiceConf: '',
|
|
|
|
});
|
|
|
|
|
2017-06-19 21:13:35 +08:00
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Adding user to collection: ${err}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Do we really need to request the stun/turn everytime?
|
2017-06-28 06:14:53 +08:00
|
|
|
// requestStunTurn(meetingId, userId);
|
2017-06-19 21:13:35 +08:00
|
|
|
|
|
|
|
const { insertedId } = numChanged;
|
|
|
|
if (insertedId) {
|
|
|
|
return Logger.info(`Added user id=${userId} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
|
2017-07-17 20:00:18 +08:00
|
|
|
return Logger.info(`Upserted user id=${userId} meeting=${meetingId}`);
|
2017-06-19 21:13:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Users.upsert(selector, modifier, cb);
|
|
|
|
}
|