2017-08-01 03:36:41 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import VoiceUsers from '/imports/api/voice-users';
|
2017-08-01 03:36:41 +08:00
|
|
|
import flat from 'flat';
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
export default async function addVoiceUser(meetingId, voiceUser) {
|
2017-08-01 03:36:41 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(voiceUser, {
|
|
|
|
voiceUserId: String,
|
|
|
|
intId: String,
|
2017-08-01 21:10:12 +08:00
|
|
|
callerName: String,
|
|
|
|
callerNum: String,
|
2023-04-19 23:16:35 +08:00
|
|
|
color: 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-14 00:24:38 +08:00
|
|
|
const { intId, talking } = 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 = {
|
2023-04-19 23:16:35 +08:00
|
|
|
$set: {
|
|
|
|
meetingId,
|
|
|
|
spoke: talking,
|
|
|
|
...flat(voiceUser),
|
2019-11-06 01:10:59 +08:00
|
|
|
},
|
2023-04-19 23:16:35 +08:00
|
|
|
};
|
2017-08-01 03:36:41 +08:00
|
|
|
|
2020-11-25 21:54:18 +08:00
|
|
|
try {
|
2023-04-01 04:40:41 +08:00
|
|
|
const { numberAffected } = await VoiceUsers.upsertAsync(selector, modifier);
|
2017-08-01 03:36:41 +08:00
|
|
|
|
2020-11-25 21:54:18 +08:00
|
|
|
if (numberAffected) {
|
|
|
|
Logger.info(`Add voice user=${intId} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Add voice user=${intId}: ${err}`);
|
|
|
|
}
|
2017-08-01 03:36:41 +08:00
|
|
|
}
|