Skip to content

Commit

Permalink
Fix packet loss calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Dec 12, 2024
1 parent 1f24555 commit 9e077e3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions broadcaster/assets/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,27 @@ async function connectInput() {
}
});

let packetLoss = 0;
let packetsLost = 0;
let packetsReceived = 0;
// calculate packet loss
if (stats.lastAudioReport) {
packetLoss += stats.lastAudioReport.packetsLost;
packetsLost += stats.lastAudioReport.packetsLost;
packetsReceived += stats.lastAudioReport.packetsReceived;
}

if (stats.lastVideoReport) {
packetLoss += stats.lastVideoReport.packetsLost;
packetsLost += stats.lastVideoReport.packetsLost;
packetsReceived += stats.lastVideoReport.packetsReceived;

}

if (packetsReceived == 0) {
stats.packetLoss.innerText = 0;
} else {
stats.packetLoss.innerText = (packetsLost / packetsReceived * 100).toFixed(2);
}

stats.packetLoss.innerText = packetLoss;

}, 1000);
} else if (view.pc.connectionState === "failed") {
}
Expand Down

0 comments on commit 9e077e3

Please sign in to comment.