2017-08-01 03:36:41 +08:00
|
|
|
import { Match, 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';
|
|
|
|
|
2019-11-14 00:24:38 +08:00
|
|
|
const TALKING_TIMEOUT = 3000;
|
|
|
|
|
2017-10-18 20:30:33 +08:00
|
|
|
export default function updateVoiceUser(meetingId, voiceUser) {
|
2017-08-01 03:36:41 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(voiceUser, {
|
|
|
|
intId: String,
|
|
|
|
voiceUserId: String,
|
|
|
|
talking: Match.Maybe(Boolean),
|
|
|
|
muted: Match.Maybe(Boolean),
|
2017-08-01 21:10:12 +08:00
|
|
|
voiceConf: String,
|
2018-03-08 00:07:17 +08:00
|
|
|
joined: Match.Maybe(Boolean),
|
2017-08-01 03:36:41 +08:00
|
|
|
});
|
|
|
|
|
2017-08-02 00:04:20 +08:00
|
|
|
const { intId } = voiceUser;
|
|
|
|
|
2017-08-01 03:36:41 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2017-08-02 00:04:20 +08:00
|
|
|
intId,
|
2017-08-01 03:36:41 +08:00
|
|
|
};
|
|
|
|
|
2019-11-06 01:10:59 +08:00
|
|
|
const modifier = {
|
2017-08-01 03:36:41 +08:00
|
|
|
$set: Object.assign(
|
|
|
|
flat(voiceUser),
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
2019-11-02 03:29:33 +08:00
|
|
|
if (voiceUser.talking) {
|
2019-11-14 00:24:38 +08:00
|
|
|
modifier.$set.spoke = true;
|
2019-11-06 01:10:59 +08:00
|
|
|
modifier.$set.startTime = new Date().getTime();
|
2019-11-14 00:24:38 +08:00
|
|
|
modifier.$set.endTime = null;
|
2019-11-02 03:29:33 +08:00
|
|
|
}
|
|
|
|
|
2017-08-01 03:36:41 +08:00
|
|
|
const cb = (err) => {
|
|
|
|
if (err) {
|
2017-08-02 00:04:20 +08:00
|
|
|
return Logger.error(`Update voiceUser=${intId}: ${err}`);
|
2017-08-01 03:36:41 +08:00
|
|
|
}
|
|
|
|
|
2019-03-18 21:12:25 +08:00
|
|
|
return Logger.debug(`Update voiceUser=${intId} meeting=${meetingId}`);
|
2017-08-01 03:36:41 +08:00
|
|
|
};
|
|
|
|
|
2019-11-14 00:24:38 +08:00
|
|
|
if (!voiceUser.talking) {
|
|
|
|
Meteor.setTimeout(() => {
|
|
|
|
const user = VoiceUsers.findOne({ meetingId, intId }, {
|
|
|
|
fields: {
|
|
|
|
endTime: 1,
|
|
|
|
talking: 1,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
const { endTime, talking } = user;
|
|
|
|
const spokeDelay = ((new Date().getTime() - endTime) < TALKING_TIMEOUT);
|
|
|
|
if (talking || spokeDelay) return;
|
|
|
|
modifier.$set.spoke = false;
|
|
|
|
VoiceUsers.update(selector, modifier, cb);
|
|
|
|
}
|
|
|
|
}, TALKING_TIMEOUT);
|
|
|
|
|
|
|
|
modifier.$set.endTime = new Date().getTime();
|
|
|
|
}
|
|
|
|
|
2017-08-01 21:10:12 +08:00
|
|
|
return VoiceUsers.update(selector, modifier, cb);
|
2017-08-01 03:36:41 +08:00
|
|
|
}
|