Skip to content

Commit 2b97c1c

Browse files
authored
feat: Added debug stats to MOS output
1 parent 2daeb9d commit 2b97c1c

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ const webRtcIssueDetector = new WebRTCIssueDetector({
2828
onIssues: (issues) => issues.map((issue) => {
2929
console.log('Issues type:', issue.type); // eg. "network"
3030
console.log('Issues reason:', issue.reason); // eg. "outbound-network-throughput"
31-
console.log('Issues reason:', issue.statsSample); // eg. "packetLossPct: 12%, avgJitter: 230, rtt: 150"
31+
console.log('Stats:', issue.statsSample); // eg. "packetLossPct: 12%, avgJitter: 230, rtt: 150"
3232
}),
3333
onNetworkScoresUpdated: (scores) => {
3434
console.log('Inbound network score', scores.inbound); // eg. 3.7
3535
console.log('Outbound network score', scores.outbound); // eg. 4.5
36+
console.log('Network stats', scores.statsSamples); // eg. { inboundStatsSample: { avgJitter: 0.1, rtt: 30, packetsLoss: 8 }, ... }
3637
}
3738
});
3839

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webrtc-issue-detector",
3-
"version": "1.6.0",
3+
"version": "1.7.0-mos-additional-debug.2",
44
"description": "WebRTC diagnostic tool that detects issues with network or user devices",
55
"repository": "git@github.com:VLprojects/webrtc-issue-detector.git",
66
"author": "Roman Kuzakov <roman.kuzakov@gmail.com>",

src/NetworkScoresCalculator.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ import {
44
NetworkScores,
55
INetworkScoresCalculator,
66
WebRTCStatsParsed,
7+
NetworkQualityStatsSample,
78
} from './types';
89
import { scheduleTask } from './utils/tasks';
910
import { CLEANUP_PREV_STATS_TTL_MS } from './utils/constants';
1011

12+
type MosCalculatorResult = {
13+
mos: NetworkScore,
14+
stats: NetworkQualityStatsSample,
15+
};
16+
1117
class NetworkScoresCalculator implements INetworkScoresCalculator {
1218
#lastProcessedStats: { [connectionId: string]: WebRTCStatsParsed } = {};
1319

1420
calculate(data: WebRTCStatsParsed): NetworkScores {
1521
const { connection: { id: connectionId } } = data;
16-
const outbound = this.calculateOutboundScore(data);
17-
const inbound = this.calculateInboundScore(data);
22+
const { mos: outbound, stats: outboundStatsSample } = this.calculateOutboundScore(data) || {};
23+
const { mos: inbound, stats: inboundStatsSample } = this.calculateInboundScore(data) || {};
1824
this.#lastProcessedStats[connectionId] = data;
1925

2026
scheduleTask({
@@ -23,10 +29,17 @@ class NetworkScoresCalculator implements INetworkScoresCalculator {
2329
callback: () => (delete this.#lastProcessedStats[connectionId]),
2430
});
2531

26-
return { outbound, inbound };
32+
return {
33+
outbound,
34+
inbound,
35+
statsSamples: {
36+
inboundStatsSample,
37+
outboundStatsSample,
38+
},
39+
};
2740
}
2841

29-
private calculateOutboundScore(data: WebRTCStatsParsed): NetworkScore | undefined {
42+
private calculateOutboundScore(data: WebRTCStatsParsed): MosCalculatorResult | undefined {
3043
const remoteInboundRTPStreamsStats = [
3144
...data.remote?.audio.inbound || [],
3245
...data.remote?.video.inbound || [],
@@ -75,10 +88,14 @@ class NetworkScoresCalculator implements INetworkScoresCalculator {
7588
? Math.round((deltaPacketLost * 100) / (deltaPacketSent + deltaPacketLost))
7689
: 0;
7790

78-
return this.calculateMOS({ avgJitter, rtt, packetsLoss });
91+
const mos = this.calculateMOS({ avgJitter, rtt, packetsLoss });
92+
return {
93+
mos,
94+
stats: { avgJitter, rtt, packetsLoss },
95+
};
7996
}
8097

81-
private calculateInboundScore(data: WebRTCStatsParsed): NetworkScore | undefined {
98+
private calculateInboundScore(data: WebRTCStatsParsed): MosCalculatorResult | undefined {
8299
const inboundRTPStreamsStats = [...data.audio?.inbound, ...data.video?.inbound];
83100
if (!inboundRTPStreamsStats.length) {
84101
return undefined;
@@ -117,7 +134,11 @@ class NetworkScoresCalculator implements INetworkScoresCalculator {
117134
? Math.round((deltaPacketLost * 100) / (deltaPacketReceived + deltaPacketLost))
118135
: 0;
119136

120-
return this.calculateMOS({ avgJitter, rtt, packetsLoss });
137+
const mos = this.calculateMOS({ avgJitter, rtt, packetsLoss });
138+
return {
139+
mos,
140+
stats: { avgJitter, rtt, packetsLoss },
141+
};
121142
}
122143

123144
private calculateMOS(

src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,19 @@ export type DetectIssuesPayload = {
9999

100100
export type NetworkScore = number;
101101

102+
export type NetworkQualityStatsSample = {
103+
avgJitter: number;
104+
rtt: number;
105+
packetsLoss: number;
106+
};
107+
102108
export type NetworkScores = {
103109
outbound?: NetworkScore,
104110
inbound?: NetworkScore,
111+
statsSamples: {
112+
outboundStatsSample?: NetworkQualityStatsSample,
113+
inboundStatsSample?: NetworkQualityStatsSample,
114+
},
105115
};
106116

107117
export type StatsParsingFinishedPayload = {

0 commit comments

Comments
 (0)