UNPKG

@observertc/client-monitor-js

Version:

ObserveRTC Client Integration Javascript Library

1 lines 1.29 kB
export class CpuPerformanceDetector{clientMonitor;static ISSUE_TYPE="cpulimitation";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:e,highWatermark:o}=this.config.fpsVolatilityThresholds??{};if(this.config.durationOfCollectingStatsThreshold){const{lowWatermark:e,highWatermark:o}=this.config.durationOfCollectingStatsThreshold;t?i=e<this.clientMonitor.durationOfCollectingStatsInMs:o<this.clientMonitor.durationOfCollectingStatsInMs&&(i=!0)}for(const t of this.clientMonitor.outboundRtps)i||="cpu"===t.qualityLimitationReason;if(e&&o)for(const n of this.clientMonitor.inboundRtps)i||n.fpsVolatility&&(!n.avgFramesPerSec||n.avgFramesPerSec<10||(t?i=e<n.fpsVolatility:o<n.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:CpuPerformanceDetector.ISSUE_TYPE})}else{if(!t)return;this.clientMonitor.cpuPerformanceAlertOn=!1,this._resolveIssue()}}_resolveIssue(){return this.clientMonitor.resolveActiveIssues(CpuPerformanceDetector.ISSUE_TYPE,(()=>!0))}}