Skip to content

Commit

Permalink
feat: Add configurable params for detectors that could support them (#24
Browse files Browse the repository at this point in the history
)

* make InboundNetworkIssueDetector consistent with other detectors

* make params configurable for network media sync and outbound network

* restore export to not cause breakages

* retrigger checks

* add blank lines in between class variables
  • Loading branch information
MFarejowicz authored Jul 15, 2024
1 parent 859163d commit c3e2481
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
28 changes: 14 additions & 14 deletions src/detectors/InboundNetworkIssueDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ 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;
highRttThresholdMs?: number;
}

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 {
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 13 additions & 2 deletions src/detectors/NetworkMediaSyncIssueDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -45,7 +56,7 @@ class NetworkMediaSyncIssueDetector extends BaseIssueDetector {
correctedSamplesPct,
};

if (correctedSamplesPct > 5) {
if (correctedSamplesPct > this.#correctedSamplesThresholdPct) {
issues.push({
statsSample,
type: IssueType.Network,
Expand Down
21 changes: 18 additions & 3 deletions src/detectors/OutboundNetworkIssueDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit c3e2481

Please sign in to comment.