bigbluebutton-Github/bigbluebutton-html5/imports/api/voice-users/server/modifiers/addVoiceUser.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-08-01 03:36:41 +08:00
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import VoiceUsers from '/imports/api/voice-users';
import Users from '/imports/api/users';
2017-08-01 03:36:41 +08:00
import flat from 'flat';
export default function addVoiceUser(meetingId, voiceUser) {
check(meetingId, String);
check(voiceUser, {
voiceUserId: String,
intId: String,
2017-08-01 21:10:12 +08:00
callerName: String,
callerNum: String,
2017-08-01 03:36:41 +08:00
muted: Boolean,
talking: Boolean,
callingWith: String,
2017-08-01 21:10:12 +08:00
listenOnly: Boolean,
voiceConf: String,
2017-08-02 21:11:53 +08:00
joined: Boolean, // This is a HTML5 only param.
2017-08-01 03:36:41 +08:00
});
2019-11-06 04:19:50 +08:00
const { intId } = voiceUser;
2017-08-01 21:10:12 +08:00
2017-08-01 03:36:41 +08:00
const selector = {
meetingId,
2017-08-01 21:10:12 +08:00
intId,
2017-08-01 03:36:41 +08:00
};
2019-11-06 04:19:50 +08:00
const modifier = {
$set: Object.assign(
flat(voiceUser),
),
};
const user = Users.findOne({ meetingId, userId: intId }, {
fields: {
color: 1,
},
});
2019-11-06 04:19:50 +08:00
if (user) modifier.$set.color = user.color;
2017-08-01 03:36:41 +08:00
const cb = (err) => {
if (err) {
2017-08-01 21:10:12 +08:00
return Logger.error(`Add voice user=${intId}: ${err}`);
2017-08-01 03:36:41 +08:00
}
return Logger.info(`Add voice user=${intId} meeting=${meetingId}`);
2017-08-01 03:36:41 +08:00
};
2017-08-01 21:10:12 +08:00
return VoiceUsers.upsert(selector, modifier, cb);
2017-08-01 03:36:41 +08:00
}