Merge pull request #20937 from Tainan404/fix-connection-status

Fix: connection status issues
This commit is contained in:
Ramón Souza 2024-08-19 16:24:05 -03:00 committed by GitHub
commit 91b5b7cb5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 51 deletions

View File

@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react';
import { useMutation } from '@apollo/client';
import { UPDATE_CONNECTION_ALIVE_AT } from './mutations';
import { getStatus, handleAudioStatsEvent, startMonitoringNetwork } from '/imports/ui/components/connection-status/service';
import { getStatus, startMonitoringNetwork } from '/imports/ui/components/connection-status/service';
import connectionStatus from '../../core/graphql/singletons/connectionStatus';
import getBaseUrl from '/imports/ui/core/utils/getBaseUrl';
@ -23,7 +23,7 @@ const ConnectionStatus = () => {
if (res.ok && res.status === 200) {
const rttLevels = window.meetingClientSettings.public.stats.rtt;
const endTime = performance.now();
const networkRtt = endTime - startTime;
const networkRtt = Math.round(endTime - startTime);
networkRttInMs.current = networkRtt;
updateConnectionAliveAtM({
variables: {
@ -62,15 +62,10 @@ const ConnectionStatus = () => {
const STATS_ENABLED = window.meetingClientSettings.public.stats.enabled;
if (STATS_ENABLED) {
window.addEventListener('audiostats', handleAudioStatsEvent);
startMonitoringNetwork();
}
return () => {
if (STATS_ENABLED) {
window.removeEventListener('audiostats', handleAudioStatsEvent);
}
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}

View File

@ -34,37 +34,28 @@ export const getHelp = () => {
return null;
};
export function getStatus(levels, value) {
const sortedLevels = Object.entries(levels)
.map((entry) => [entry[0], Number(entry[1])])
.sort((a, b) => a[1] - b[1]);
for (let i = 0; i < sortedLevels.length; i += 1) {
if (value < sortedLevels[i][1]) {
return i === 0 ? 'normal' : sortedLevels[i - 1][0];
}
if (i === sortedLevels.length - 1) {
return sortedLevels[i][0];
}
}
return sortedLevels[sortedLevels.length - 1][0];
}
export const getStats = () => {
const STATS = window.meetingClientSettings.public.stats;
return STATS.level[lastLevel()];
};
export const setStats = (level = -1, type = 'recovery', value = {}) => {
if (lastLevel() !== level) {
lastLevel(level);
}
};
export const handleAudioStatsEvent = (event) => {
const STATS = window.meetingClientSettings.public.stats;
const { detail } = event;
if (detail) {
const { loss, jitter } = detail;
let active = false;
// From higher to lower
for (let i = STATS.level.length - 1; i >= 0; i--) {
if (loss >= STATS.loss[i] || jitter >= STATS.jitter[i]) {
active = true;
setStats(i, 'audio', { loss, jitter });
break;
}
}
if (active) startStatsTimeout();
}
};
export const startStatsTimeout = () => {
const STATS = window.meetingClientSettings.public.stats;
@ -381,23 +372,6 @@ export const calculateBitsPerSecondFromMultipleData = (currentData, previousData
const sortConnectionData = (connectionData) => connectionData.sort(sortLevel).sort(sortOnline);
export function getStatus(levels, value) {
const sortedLevels = Object.entries(levels)
.map((entry) => [entry[0], Number(entry[1])])
.sort((a, b) => a[1] - b[1]);
for (let i = 0; i < sortedLevels.length; i += 1) {
if (value < sortedLevels[i][1]) {
return i === 0 ? 'normal' : sortedLevels[i - 1][0];
}
if (i === sortedLevels.length - 1) {
return sortedLevels[i][0];
}
}
return sortedLevels[sortedLevels.length - 1][0];
}
/**
* Start monitoring the network data.
* @return {Promise} A Promise that resolves when process started.
@ -487,7 +461,6 @@ export default {
calculateBitsPerSecondFromMultipleData,
getDataType,
sortConnectionData,
handleAudioStatsEvent,
startMonitoringNetwork,
getStatus,
getWorstStatus,