UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 1.11 kB
export class CpuPerformanceDetector{clientMonitor;name="cpu-performance-detector";constructor(t){this.clientMonitor=t}get config(){return this.clientMonitor.config.cpuPerformanceDetector}update(){const t=this.clientMonitor.cpuPerformanceAlertOn;let i=!1;const{lowWatermark:o,highWatermark:n}=this.config.fpsVolatilityThresholds??{};if(this.config.durationOfCollectingStatsThreshold){const{lowWatermark:o,highWatermark:n}=this.config.durationOfCollectingStatsThreshold;t?i=o<this.clientMonitor.durationOfCollectingStatsInMs:n<this.clientMonitor.durationOfCollectingStatsInMs&&(i=!0)}for(const t of this.clientMonitor.outboundRtps)i||="cpu"===t.qualityLimitationReason;if(o&&n)for(const e of this.clientMonitor.inboundRtps)i||e.fpsVolatility&&(!e.avgFramesPerSec||e.avgFramesPerSec<10||(t?i=o<e.fpsVolatility:n<e.fpsVolatility&&(i=!0)));if(i){if(t)return;this.clientMonitor.cpuPerformanceAlertOn=!0,this.clientMonitor.emit("cpulimitation",{clientMonitor:this.clientMonitor}),this.config.createIssue&&this.clientMonitor.addIssue({type:"cpulimitation"})}else{if(!t)return;this.clientMonitor.cpuPerformanceAlertOn=!1}}}