Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add configurable params for detectors that could support them #24

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
evgmel marked this conversation as resolved.
Show resolved Hide resolved

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;
evgmel marked this conversation as resolved.
Show resolved Hide resolved

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