bigbluebutton-Github/bigbluebutton-html5/imports/api/voice-users/server/modifiers/updateVoiceUser.js
2019-11-05 20:19:50 +00:00

44 lines
960 B
JavaScript

import { Match, check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import VoiceUsers from '/imports/api/voice-users';
import flat from 'flat';
export default function updateVoiceUser(meetingId, voiceUser) {
check(meetingId, String);
check(voiceUser, {
intId: String,
voiceUserId: String,
talking: Match.Maybe(Boolean),
muted: Match.Maybe(Boolean),
voiceConf: String,
joined: Match.Maybe(Boolean),
});
const { intId } = voiceUser;
const selector = {
meetingId,
intId,
};
const modifier = {
$set: Object.assign(
flat(voiceUser),
),
};
if (voiceUser.talking) {
modifier.$set.startTime = new Date().getTime();
}
const cb = (err) => {
if (err) {
return Logger.error(`Update voiceUser=${intId}: ${err}`);
}
return Logger.debug(`Update voiceUser=${intId} meeting=${meetingId}`);
};
return VoiceUsers.update(selector, modifier, cb);
}