В модуль stats.js
вынесены функции проверки параметров WebRTC статистики и выявления скачков параметров выше заданного предела
Для анализа исходного кода возьмем версию модуля stats.js
, которая находится здесь
Threshold()
code
Здесь:
const threshold = { parameter: parameter, maxLeap: maxLeap, filter: SFU.createFilter(), previousValue: -1, ... } |
Threshold.isReached()
code
Здесь:
isReached: function(stats) { let hasLeap = false; if (stats && parameter in stats) { let value = threshold.filter.filter(stats[parameter]); if (threshold.previousValue > -1) { if (Math.round(Math.abs(value - threshold.previousValue)) > maxLeap) { hasLeap = true; } } threshold.previousValue = value; } return hasLeap; } |
Thresholds.add()
code
add: function(parameter, maxLeap) { if (!thresholds.thresholds[parameter]) { thresholds.thresholds[parameter] = new Threshold(parameter, maxLeap); } }, |
Thresholds.remove()
code
remove: function(parameter) { if (thresholds.thresholds[parameter]) { delete thresholds.thresholds[parameter]; } }, |
Thresholds.isReached()
code
isReached: function(stats) { let result = false; Object.keys(thresholds.thresholds).forEach((key) => { result = result || thresholds.thresholds[key].isReached(stats); }); return result; } |