Connection status back-end migrated to new async API

This commit is contained in:
imdt 2023-03-10 09:06:13 -03:00 committed by Ramón Souza
parent a5dea6f595
commit 5add111aa9
5 changed files with 25 additions and 22 deletions

View File

@ -7,7 +7,7 @@ const collectionOptions = Meteor.isClient ? {
const ConnectionStatus = new Mongo.Collection('connection-status', collectionOptions);
if (Meteor.isServer) {
ConnectionStatus._ensureIndex({ meetingId: 1, userId: 1 });
ConnectionStatus.createIndexAsync({ meetingId: 1, userId: 1 });
}
export default ConnectionStatus;

View File

@ -1,7 +1,7 @@
import ConnectionStatus from '/imports/api/connection-status';
import Logger from '/imports/startup/server/logger';
export default function clearConnectionStatus(meetingId) {
export default async function clearConnectionStatus(meetingId) {
const selector = {};
if (meetingId) {
@ -9,7 +9,7 @@ export default function clearConnectionStatus(meetingId) {
}
try {
const numberAffected = ConnectionStatus.remove(selector);
const numberAffected = await ConnectionStatus.removeAsync(selector);
if (numberAffected) {
if (meetingId) {

View File

@ -7,7 +7,7 @@ const STATS = Meteor.settings.public.stats;
const STATS_INTERVAL = STATS.interval;
const STATS_CRITICAL_RTT = STATS.rtt[STATS.rtt.length - 1];
export default function updateConnectionStatus(meetingId, userId, status) {
export default async function updateConnectionStatus(meetingId, userId, status) {
check(meetingId, String);
check(userId, String);
@ -32,14 +32,15 @@ export default function updateConnectionStatus(meetingId, userId, status) {
}
try {
const { numberAffected } = ConnectionStatus.upsert(selector, { $set: modifier });
const { numberAffected } = await ConnectionStatus.upsertAsync(selector, { $set: modifier });
if (numberAffected && status !== 'normal') {
changeHasConnectionStatus(true, userId, meetingId);
await changeHasConnectionStatus(true, userId, meetingId);
Logger.verbose(`Updated connection status meetingId=${meetingId} userId=${userId} status=${status}`);
}
Meteor.setTimeout(() => {
const connectionLossTimeThreshold = new Date().getTime() - (STATS_INTERVAL + STATS_CRITICAL_RTT);
Meteor.setTimeout(async () => {
const connectionLossTimeThreshold = new Date()
.getTime() - (STATS_INTERVAL + STATS_CRITICAL_RTT);
const selectorNotResponding = {
meetingId,
@ -48,15 +49,15 @@ export default function updateConnectionStatus(meetingId, userId, status) {
clientNotResponding: false,
};
const numberAffectedNotResponding = ConnectionStatus.update(selectorNotResponding, {
$set: { clientNotResponding: true }
});
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}`);
}

View File

@ -8,8 +8,9 @@ import { publicationSafeGuard } from '/imports/api/common/server/helpers';
const ROLE_MODERATOR = Meteor.settings.public.user.role_moderator;
function connectionStatus() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
async function connectionStatus() {
const tokenValidation = await AuthTokenValidation
.findOneAsync({ connectionId: this.connection.id });
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing ConnectionStatus was requested by unauth connection ${this.connection.id}`);
@ -27,15 +28,16 @@ function connectionStatus() {
status: 1,
statusUpdatedAt: 1,
clientNotResponding: 1,
}
};
const User = Users.findOne({ userId, meetingId }, { fields: { role: 1 } });
const User = await Users.findOneAsync({ userId, meetingId }, { fields: { role: 1 } });
Logger.info(`Publishing connection status for ${meetingId} ${userId}`);
if (!!User && User.role === ROLE_MODERATOR) {
// Monitor this publication and stop it when user is not a moderator anymore
const comparisonFunc = () => {
const user = Users.findOne({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
const comparisonFunc = async () => {
const user = await Users
.findOneAsync({ userId, meetingId }, { fields: { role: 1, userId: 1 } });
const condition = user.role === ROLE_MODERATOR;
if (!condition) {
@ -46,10 +48,10 @@ function connectionStatus() {
return condition;
};
publicationSafeGuard(comparisonFunc, this);
return ConnectionStatus.find({ meetingId }, { fields: fields });
return ConnectionStatus.find({ meetingId }, { fields });
}
return ConnectionStatus.find({ meetingId, userId }, { fields: fields });
return ConnectionStatus.find({ meetingId, userId }, { fields });
}
function publish(...args) {

View File

@ -1,7 +1,7 @@
import Logger from '/imports/startup/server/logger';
import UsersPersistentData from '/imports/api/users-persistent-data';
export default function changeHasConnectionStatus(hasConnectionStatus, userId, meetingId) {
export default async function changeHasConnectionStatus(hasConnectionStatus, userId, meetingId) {
const selector = {
meetingId,
userId,
@ -14,7 +14,7 @@ export default function changeHasConnectionStatus(hasConnectionStatus, userId, m
};
try {
const numberAffected = UsersPersistentData.update(selector, modifier);
const numberAffected = await UsersPersistentData.updateAsync(selector, modifier);
if (numberAffected) {
Logger.info(`Changed hasConnectionStatus=${hasConnectionStatus} id=${userId} meeting=${meetingId}`);