Skip to content

Commit c3e2481

Browse files
authored
feat: Add configurable params for detectors that could support them (#24)
* 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
1 parent 859163d commit c3e2481

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

src/detectors/InboundNetworkIssueDetector.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ import {
44
IssueType,
55
WebRTCStatsParsed,
66
} from '../types';
7-
import BaseIssueDetector from './BaseIssueDetector';
7+
import BaseIssueDetector, { BaseIssueDetectorParams } from './BaseIssueDetector';
88

9-
export interface InboundNetworkIssueDetectorParams {
9+
export interface InboundNetworkIssueDetectorParams extends BaseIssueDetectorParams {
1010
highPacketLossThresholdPct?: number;
1111
highJitterThreshold?: number;
1212
highJitterBufferDelayThresholdMs?: number;
1313
highRttThresholdMs?: number;
1414
}
1515

1616
class InboundNetworkIssueDetector extends BaseIssueDetector {
17-
readonly highPacketLossThresholdPct: number;
17+
readonly #highPacketLossThresholdPct: number;
1818

19-
readonly highJitterThreshold: number;
19+
readonly #highJitterThreshold: number;
2020

21-
readonly highJitterBufferDelayThresholdMs: number;
21+
readonly #highJitterBufferDelayThresholdMs: number;
2222

23-
readonly highRttThresholdMs: number;
23+
readonly #highRttThresholdMs: number;
2424

2525
constructor(params: InboundNetworkIssueDetectorParams = {}) {
2626
super();
27-
this.highPacketLossThresholdPct = params.highPacketLossThresholdPct ?? 5;
28-
this.highJitterThreshold = params.highJitterThreshold ?? 200;
29-
this.highJitterBufferDelayThresholdMs = params.highJitterBufferDelayThresholdMs ?? 500;
30-
this.highRttThresholdMs = params.highRttThresholdMs ?? 250;
27+
this.#highPacketLossThresholdPct = params.highPacketLossThresholdPct ?? 5;
28+
this.#highJitterThreshold = params.highJitterThreshold ?? 200;
29+
this.#highJitterBufferDelayThresholdMs = params.highJitterBufferDelayThresholdMs ?? 500;
30+
this.#highRttThresholdMs = params.highRttThresholdMs ?? 250;
3131
}
3232

3333
performDetection(data: WebRTCStatsParsed): IssueDetectorResult {
@@ -87,10 +87,10 @@ class InboundNetworkIssueDetector extends BaseIssueDetector {
8787
? Math.round((deltaPacketLost * 100) / (deltaPacketReceived + deltaPacketLost))
8888
: 0;
8989

90-
const isHighPacketsLoss = packetLossPct > this.highPacketLossThresholdPct;
91-
const isHighJitter = avgJitter >= this.highJitterThreshold;
92-
const isHighRTT = rtt >= this.highRttThresholdMs;
93-
const isHighJitterBufferDelay = avgJitterBufferDelay > this.highJitterBufferDelayThresholdMs;
90+
const isHighPacketsLoss = packetLossPct > this.#highPacketLossThresholdPct;
91+
const isHighJitter = avgJitter >= this.#highJitterThreshold;
92+
const isHighRTT = rtt >= this.#highRttThresholdMs;
93+
const isHighJitterBufferDelay = avgJitterBufferDelay > this.#highJitterBufferDelayThresholdMs;
9494
const isNetworkIssue = isHighJitter || isHighPacketsLoss;
9595
const isServerIssue = isHighRTT && !isHighJitter && !isHighPacketsLoss;
9696
const isNetworkMediaLatencyIssue = isHighPacketsLoss && isHighJitter;

src/detectors/NetworkMediaSyncIssueDetector.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@ import {
44
IssueType,
55
WebRTCStatsParsed,
66
} from '../types';
7-
import BaseIssueDetector from './BaseIssueDetector';
7+
import BaseIssueDetector, { BaseIssueDetectorParams } from './BaseIssueDetector';
8+
9+
interface NetworkMediaSyncIssueDetectorParams extends BaseIssueDetectorParams {
10+
correctedSamplesThresholdPct?: number
11+
}
812

913
class NetworkMediaSyncIssueDetector extends BaseIssueDetector {
14+
readonly #correctedSamplesThresholdPct: number;
15+
16+
constructor(params: NetworkMediaSyncIssueDetectorParams = {}) {
17+
super();
18+
this.#correctedSamplesThresholdPct = params.correctedSamplesThresholdPct ?? 5;
19+
}
20+
1021
performDetection(data: WebRTCStatsParsed): IssueDetectorResult {
1122
const { connection: { id: connectionId } } = data;
1223
const issues = this.processData(data);
@@ -45,7 +56,7 @@ class NetworkMediaSyncIssueDetector extends BaseIssueDetector {
4556
correctedSamplesPct,
4657
};
4758

48-
if (correctedSamplesPct > 5) {
59+
if (correctedSamplesPct > this.#correctedSamplesThresholdPct) {
4960
issues.push({
5061
statsSample,
5162
type: IssueType.Network,

src/detectors/OutboundNetworkIssueDetector.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,24 @@ import {
44
IssueType,
55
WebRTCStatsParsed,
66
} from '../types';
7-
import BaseIssueDetector from './BaseIssueDetector';
7+
import BaseIssueDetector, { BaseIssueDetectorParams } from './BaseIssueDetector';
8+
9+
interface OutboundNetworkIssueDetectorParams extends BaseIssueDetectorParams {
10+
highPacketLossThresholdPct?: number;
11+
highJitterThreshold?: number;
12+
}
813

914
class OutboundNetworkIssueDetector extends BaseIssueDetector {
15+
readonly #highPacketLossThresholdPct: number;
16+
17+
readonly #highJitterThreshold: number;
18+
19+
constructor(params: OutboundNetworkIssueDetectorParams = {}) {
20+
super();
21+
this.#highPacketLossThresholdPct = params.highPacketLossThresholdPct ?? 5;
22+
this.#highJitterThreshold = params.highJitterThreshold ?? 200;
23+
}
24+
1025
performDetection(data: WebRTCStatsParsed): IssueDetectorResult {
1126
const { connection: { id: connectionId } } = data;
1227
const issues = this.processData(data);
@@ -64,8 +79,8 @@ class OutboundNetworkIssueDetector extends BaseIssueDetector {
6479
? Math.round((deltaPacketLost * 100) / (deltaPacketSent + deltaPacketLost))
6580
: 0;
6681

67-
const isHighPacketsLoss = packetLossPct > 5;
68-
const isHighJitter = avgJitter >= 200;
82+
const isHighPacketsLoss = packetLossPct > this.#highPacketLossThresholdPct;
83+
const isHighJitter = avgJitter >= this.#highJitterThreshold;
6984
const isNetworkMediaLatencyIssue = isHighPacketsLoss && isHighJitter;
7085
const isNetworkIssue = (!isHighPacketsLoss && isHighJitter) || isHighJitter || isHighPacketsLoss;
7186

0 commit comments

Comments
 (0)