Skip to content

Commit

Permalink
Final edit
Browse files Browse the repository at this point in the history
  • Loading branch information
ehfd authored May 20, 2024
1 parent f35de4c commit 10fefe6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions addons/gst-web/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ function onBothStreamConnected() {
audio_webrtc.peerConnection.getReceivers().forEach(receiver => {
receiver.jitterBufferTarget = receiver.jitterBufferDelayHint = receiver.playoutDelayHint = 0.0;
});
// Start watching stats.
// Start watching stats
var videoBytesReceivedStart = 0;
var audioBytesReceivedStart = 0;
var statsStart = new Date().getTime() / 1000;
Expand All @@ -446,13 +446,13 @@ function onBothStreamConnected() {
if (videoConnected !== "connected" || audioConnected !== "connected") return;
var now = new Date().getTime() / 1000;

// Connection latency in ms.
// Connection latency in milliseconds
app.connectionLatency = 0;
app.connectionVideoLatency = (stats.general.currentRoundTripTime !== null) ? (stats.general.currentRoundTripTime * 1000.0) : (app.serverLatency * 2.0);
app.connectionAudioLatency = (audioStats.general.currentRoundTripTime !== null) ? (audioStats.general.currentRoundTripTime * 1000.0) : (app.serverLatency * 2.0);
app.connectionLatency += Math.max(app.connectionVideoLatency, app.connectionAudioLatency);

// Sum of video+audio packets.
// Sum of video+audio packets
app.connectionPacketsReceived = 0;
app.connectionPacketsLost = 0;

Expand All @@ -462,7 +462,7 @@ function onBothStreamConnected() {
app.connectionBytesSent = ((stats.general.bytesSent + audioStats.general.bytesSent) * 1e-6).toFixed(2) + " MBytes";
app.connectionAvailableBandwidth = ((parseInt(stats.general.availableReceiveBandwidth) + parseInt(audioStats.general.availableReceiveBandwidth)) / 1e+6).toFixed(2) + " mbps";

// Video stats.
// Video stats
app.connectionPacketsReceived += stats.video.packetsReceived;
app.connectionPacketsLost += stats.video.packetsLost;
app.connectionCodec = stats.video.codecName;
Expand All @@ -472,14 +472,14 @@ function onBothStreamConnected() {
app.connectionVideoBitrate = (((stats.video.bytesReceived - videoBytesReceivedStart) / (now - statsStart)) * 8 / 1e+6).toFixed(2);
videoBytesReceivedStart = stats.video.bytesReceived;

// Audio stats.
// Audio stats
app.connectionPacketsReceived += audioStats.audio.packetsReceived;
app.connectionPacketsLost += audioStats.audio.packetsLost;
app.connectionAudioCodecName = audioStats.audio.codecName;
app.connectionAudioBitrate = (((audioStats.audio.bytesReceived - audioBytesReceivedStart) / (now - statsStart)) * 8 / 1e+3).toFixed(2);
audioBytesReceivedStart = audioStats.audio.bytesReceived;

// Latency stats.
// Latency stats
app.connectionVideoLatency = parseInt(Math.round(app.connectionVideoLatency + (1000.0 * (stats.video.jitterBufferDelay - stats.video.previousJitterBufferDelay) / (stats.video.jitterBufferEmittedCount - stats.video.previousJitterBufferEmittedCount) || 0)));
app.connectionAudioLatency = parseInt(Math.round(app.connectionAudioLatency + (1000.0 * (audioStats.audio.jitterBufferDelay - audioStats.audio.previousJitterBufferDelay) / (audioStats.audio.jitterBufferEmittedCount - audioStats.audio.previousJitterBufferEmittedCount) || 0)));

Expand All @@ -491,7 +491,7 @@ function onBothStreamConnected() {
webrtc.sendDataChannelMessage("_stats_video," + JSON.stringify(stats.allReports));
webrtc.sendDataChannelMessage("_stats_audio," + JSON.stringify(audioStats.allReports));

// Stats refresh loop.
// Stats refresh loop
setTimeout(statsLoop, 1000);
});
});
Expand Down
4 changes: 2 additions & 2 deletions addons/gst-web/src/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class WebRTCDemo {
return new Promise(function (resolve, reject) {
// Statistics API:
// https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_Statistics_API
pc.getStats().then( (stats) => {
pc.getStats().then((stats) => {
var reports = {
transports: {},
candidatePairs: {},
Expand Down Expand Up @@ -634,7 +634,7 @@ class WebRTCDemo {
connectionDetails.data.messagesSent = dataChannel.messagesSent;
}

// Extract transport stats (RTCTransportStats.selectedCandidatePairId or RTCIceCandidatePairStats.selected).
// Extract transport stats (RTCTransportStats.selectedCandidatePairId or RTCIceCandidatePairStats.selected)
if (Object.keys(reports.transports).length > 0) {
var transport = reports.transports[Object.keys(reports.transports)[0]];
connectionDetails.general.bytesReceived = transport.bytesReceived;
Expand Down

0 comments on commit 10fefe6

Please sign in to comment.