2020-04-10 01:01:46 +08:00
|
|
|
import { check } from 'meteor/check';
|
2021-04-24 05:37:52 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2020-04-10 01:01:46 +08:00
|
|
|
import updateConnectionStatus from '/imports/api/connection-status/server/modifiers/updateConnectionStatus';
|
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
|
2021-04-24 06:15:32 +08:00
|
|
|
const STATS = Meteor.settings.public.stats;
|
|
|
|
|
2021-04-24 05:37:52 +08:00
|
|
|
const logConnectionStatus = (meetingId, userId, status, type, value) => {
|
|
|
|
switch (status) {
|
|
|
|
case 'normal':
|
2021-04-27 05:19:17 +08:00
|
|
|
Logger.info(`Connection status updated: meetingId=${meetingId} userId=${userId} status=${status} type=${type}`);
|
2021-04-24 05:37:52 +08:00
|
|
|
break;
|
|
|
|
case 'warning':
|
|
|
|
case 'danger':
|
|
|
|
case 'critical':
|
|
|
|
switch (type) {
|
2021-05-05 02:01:09 +08:00
|
|
|
case 'audio': {
|
2021-04-24 05:37:52 +08:00
|
|
|
const {
|
|
|
|
jitter,
|
|
|
|
loss,
|
|
|
|
} = value;
|
2021-04-27 05:19:17 +08:00
|
|
|
Logger.info(`Connection status updated: meetingId=${meetingId} userId=${userId} status=${status} type=${type} jitter=${jitter} loss=${loss}`);
|
2021-04-24 05:37:52 +08:00
|
|
|
break;
|
2021-05-05 02:01:09 +08:00
|
|
|
}
|
|
|
|
case 'socket': {
|
2021-04-24 05:37:52 +08:00
|
|
|
const { rtt } = value;
|
2021-04-27 05:19:17 +08:00
|
|
|
Logger.info(`Connection status updated: meetingId=${meetingId} userId=${userId} status=${status} type=${type} rtt=${rtt}`);
|
2021-04-24 05:37:52 +08:00
|
|
|
break;
|
2021-05-05 02:01:09 +08:00
|
|
|
}
|
2021-04-24 05:37:52 +08:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function addConnectionStatus(status, type, value) {
|
2021-05-05 02:01:09 +08:00
|
|
|
try {
|
|
|
|
check(status, String);
|
|
|
|
check(type, String);
|
|
|
|
check(value, Object);
|
2020-04-10 01:01:46 +08:00
|
|
|
|
2021-07-02 22:51:01 +08:00
|
|
|
if (!this.userId) return;
|
|
|
|
|
2021-05-05 02:01:09 +08:00
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
2020-04-10 01:01:46 +08:00
|
|
|
|
2021-05-05 02:01:09 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
2021-03-26 05:22:50 +08:00
|
|
|
|
2021-05-05 02:01:09 +08:00
|
|
|
if (STATS.log) logConnectionStatus(meetingId, requesterUserId, status, type, value);
|
2021-04-24 05:37:52 +08:00
|
|
|
|
2022-09-15 09:16:27 +08:00
|
|
|
updateConnectionStatus(meetingId, requesterUserId, status);
|
2021-05-05 02:01:09 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method addConnectionStatus ${err.stack}`);
|
2021-04-24 05:37:52 +08:00
|
|
|
}
|
2020-04-10 01:01:46 +08:00
|
|
|
}
|