diff --git a/src/detectors/InboundNetworkIssueDetector.ts b/src/detectors/InboundNetworkIssueDetector.ts index 2c4296f..f1736a3 100644 --- a/src/detectors/InboundNetworkIssueDetector.ts +++ b/src/detectors/InboundNetworkIssueDetector.ts @@ -4,9 +4,9 @@ import { IssueType, WebRTCStatsParsed, } from '../types'; -import BaseIssueDetector from './BaseIssueDetector'; +import BaseIssueDetector, { BaseIssueDetectorParams } from './BaseIssueDetector'; -export interface InboundNetworkIssueDetectorParams { +export interface InboundNetworkIssueDetectorParams extends BaseIssueDetectorParams { highPacketLossThresholdPct?: number; highJitterThreshold?: number; highJitterBufferDelayThresholdMs?: number; @@ -14,20 +14,20 @@ export interface InboundNetworkIssueDetectorParams { } class InboundNetworkIssueDetector extends BaseIssueDetector { - readonly highPacketLossThresholdPct: number; + readonly #highPacketLossThresholdPct: number; - readonly highJitterThreshold: number; + readonly #highJitterThreshold: number; - readonly highJitterBufferDelayThresholdMs: number; + readonly #highJitterBufferDelayThresholdMs: number; - readonly highRttThresholdMs: number; + readonly #highRttThresholdMs: number; constructor(params: InboundNetworkIssueDetectorParams = {}) { super(); - this.highPacketLossThresholdPct = params.highPacketLossThresholdPct ?? 5; - this.highJitterThreshold = params.highJitterThreshold ?? 200; - this.highJitterBufferDelayThresholdMs = params.highJitterBufferDelayThresholdMs ?? 500; - this.highRttThresholdMs = params.highRttThresholdMs ?? 250; + this.#highPacketLossThresholdPct = params.highPacketLossThresholdPct ?? 5; + this.#highJitterThreshold = params.highJitterThreshold ?? 200; + this.#highJitterBufferDelayThresholdMs = params.highJitterBufferDelayThresholdMs ?? 500; + this.#highRttThresholdMs = params.highRttThresholdMs ?? 250; } performDetection(data: WebRTCStatsParsed): IssueDetectorResult { @@ -87,10 +87,10 @@ class InboundNetworkIssueDetector extends BaseIssueDetector { ? Math.round((deltaPacketLost * 100) / (deltaPacketReceived + deltaPacketLost)) : 0; - const isHighPacketsLoss = packetLossPct > this.highPacketLossThresholdPct; - const isHighJitter = avgJitter >= this.highJitterThreshold; - const isHighRTT = rtt >= this.highRttThresholdMs; - const isHighJitterBufferDelay = avgJitterBufferDelay > this.highJitterBufferDelayThresholdMs; + const isHighPacketsLoss = packetLossPct > this.#highPacketLossThresholdPct; + const isHighJitter = avgJitter >= this.#highJitterThreshold; + const isHighRTT = rtt >= this.#highRttThresholdMs; + const isHighJitterBufferDelay = avgJitterBufferDelay > this.#highJitterBufferDelayThresholdMs; const isNetworkIssue = isHighJitter || isHighPacketsLoss; const isServerIssue = isHighRTT && !isHighJitter && !isHighPacketsLoss; const isNetworkMediaLatencyIssue = isHighPacketsLoss && isHighJitter; diff --git a/src/detectors/NetworkMediaSyncIssueDetector.ts b/src/detectors/NetworkMediaSyncIssueDetector.ts index a5c6c7a..8bacd94 100644 --- a/src/detectors/NetworkMediaSyncIssueDetector.ts +++ b/src/detectors/NetworkMediaSyncIssueDetector.ts @@ -4,9 +4,20 @@ import { IssueType, WebRTCStatsParsed, } from '../types'; -import BaseIssueDetector from './BaseIssueDetector'; +import BaseIssueDetector, { BaseIssueDetectorParams } from './BaseIssueDetector'; + +interface NetworkMediaSyncIssueDetectorParams extends BaseIssueDetectorParams { + correctedSamplesThresholdPct?: number +} class NetworkMediaSyncIssueDetector extends BaseIssueDetector { + readonly #correctedSamplesThresholdPct: number; + + constructor(params: NetworkMediaSyncIssueDetectorParams = {}) { + super(); + this.#correctedSamplesThresholdPct = params.correctedSamplesThresholdPct ?? 5; + } + performDetection(data: WebRTCStatsParsed): IssueDetectorResult { const { connection: { id: connectionId } } = data; const issues = this.processData(data); @@ -45,7 +56,7 @@ class NetworkMediaSyncIssueDetector extends BaseIssueDetector { correctedSamplesPct, }; - if (correctedSamplesPct > 5) { + if (correctedSamplesPct > this.#correctedSamplesThresholdPct) { issues.push({ statsSample, type: IssueType.Network, diff --git a/src/detectors/OutboundNetworkIssueDetector.ts b/src/detectors/OutboundNetworkIssueDetector.ts index a037e9e..95a637a 100644 --- a/src/detectors/OutboundNetworkIssueDetector.ts +++ b/src/detectors/OutboundNetworkIssueDetector.ts @@ -4,9 +4,24 @@ import { IssueType, WebRTCStatsParsed, } from '../types'; -import BaseIssueDetector from './BaseIssueDetector'; +import BaseIssueDetector, { BaseIssueDetectorParams } from './BaseIssueDetector'; + +interface OutboundNetworkIssueDetectorParams extends BaseIssueDetectorParams { + highPacketLossThresholdPct?: number; + highJitterThreshold?: number; +} class OutboundNetworkIssueDetector extends BaseIssueDetector { + readonly #highPacketLossThresholdPct: number; + + readonly #highJitterThreshold: number; + + constructor(params: OutboundNetworkIssueDetectorParams = {}) { + super(); + this.#highPacketLossThresholdPct = params.highPacketLossThresholdPct ?? 5; + this.#highJitterThreshold = params.highJitterThreshold ?? 200; + } + performDetection(data: WebRTCStatsParsed): IssueDetectorResult { const { connection: { id: connectionId } } = data; const issues = this.processData(data); @@ -64,8 +79,8 @@ class OutboundNetworkIssueDetector extends BaseIssueDetector { ? Math.round((deltaPacketLost * 100) / (deltaPacketSent + deltaPacketLost)) : 0; - const isHighPacketsLoss = packetLossPct > 5; - const isHighJitter = avgJitter >= 200; + const isHighPacketsLoss = packetLossPct > this.#highPacketLossThresholdPct; + const isHighJitter = avgJitter >= this.#highJitterThreshold; const isNetworkMediaLatencyIssue = isHighPacketsLoss && isHighJitter; const isNetworkIssue = (!isHighPacketsLoss && isHighJitter) || isHighJitter || isHighPacketsLoss;