bigbluebutton-Github/bigbluebutton-html5/imports/api/connection-status/server/modifiers/updateConnectionStatus.js

65 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-04-10 01:01:46 +08:00
import ConnectionStatus from '/imports/api/connection-status';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
2022-02-02 21:53:23 +08:00
import changeHasConnectionStatus from '/imports/api/users-persistent-data/server/modifiers/changeHasConnectionStatus';
2020-04-10 01:01:46 +08:00
const STATS = Meteor.settings.public.stats;
const STATS_INTERVAL = STATS.interval;
const STATS_CRITICAL_RTT = STATS.rtt[STATS.rtt.length - 1];
export default async function updateConnectionStatus(meetingId, userId, status) {
2020-04-10 01:01:46 +08:00
check(meetingId, String);
check(userId, String);
const now = new Date().getTime();
2020-04-10 01:01:46 +08:00
const selector = {
meetingId,
userId,
};
const modifier = {
2020-05-14 21:35:25 +08:00
meetingId,
userId,
connectionAliveAt: now,
clientNotResponding: false,
2020-04-10 01:01:46 +08:00
};
// Store last not-normal status
if (status !== 'normal') {
modifier.status = status;
modifier.statusUpdatedAt = now;
}
2020-04-10 01:01:46 +08:00
try {
const { numberAffected } = await ConnectionStatus.upsertAsync(selector, { $set: modifier });
if (numberAffected && status !== 'normal') {
await changeHasConnectionStatus(true, userId, meetingId);
Logger.verbose(`Updated connection status meetingId=${meetingId} userId=${userId} status=${status}`);
2020-05-14 21:35:25 +08:00
}
Meteor.setTimeout(async () => {
const connectionLossTimeThreshold = new Date()
.getTime() - (STATS_INTERVAL + STATS_CRITICAL_RTT);
const selectorNotResponding = {
meetingId,
userId,
connectionAliveAt: { $lte: connectionLossTimeThreshold },
clientNotResponding: false,
};
const numberAffectedNotResponding = await ConnectionStatus
.updateAsync(selectorNotResponding, {
$set: { clientNotResponding: true },
});
if (numberAffectedNotResponding) {
Logger.info(`Updated clientNotResponding=true meetingId=${meetingId} userId=${userId}`);
}
}, STATS_INTERVAL + STATS_CRITICAL_RTT);
} catch (err) {
Logger.error(`Updating connection status meetingId=${meetingId} userId=${userId}: ${err}`);
}
2020-04-10 01:01:46 +08:00
}