Skip to content

Commit

Permalink
Compatibility with new licode stats format
Browse files Browse the repository at this point in the history
  • Loading branch information
aalonsog committed Apr 20, 2017
1 parent e4f1997 commit c51d6e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
34 changes: 19 additions & 15 deletions common/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ API.api = {
}
},
stats: function(theStats) {
//log.info('Stat: ', theStats);
// log.info('Stat: ', theStats);
theStats = theStats.message;
try {
API.send_stats_to_clients(theStats);
Expand Down Expand Up @@ -415,13 +415,15 @@ API.send_stats_to_clients = function(event) {
var pubID = String(event.pub);
var stats = event.stats;
var video, audio;
if (stats && stats.length > 0) {
if (stats[0].type == "video") {
video = stats[0];
audio = stats[1];
} else {
video = stats[1];
audio = stats[0];
if (stats) {
for (var ssrc in stats) {
if (stats[ssrc].type === 'video') {
video = stats[ssrc];
video.ssrc = ssrc;
} else if (stats[ssrc].type === 'audio') {
audio = stats[ssrc];
audio.ssrc = ssrc;
}
}
}

Expand All @@ -437,13 +439,15 @@ API.send_stats_to_clients = function(event) {
var subID = event.subs;
var stats = event.stats;
var video, audio;
if (stats && stats.length > 0) {
if (stats[0].PLI) {
video = stats[0];
audio = stats[1];
} else {
video = stats[1];
audio = stats[0];
if (stats) {
for (var ssrc in stats) {
if (stats[ssrc].type === 'video') {
video = stats[ssrc];
video.ssrc = ssrc;
} else if (stats[ssrc].type === 'audio') {
audio = stats[ssrc];
audio.ssrc = ssrc;
}
}
}
for (var s in API.sockets) {
Expand Down
16 changes: 8 additions & 8 deletions public/javascripts/subscribers.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,18 @@ $(document).ready(function(){
var bpsAudio, bpsVideo, kbpsAudio, kbpsVideo;
if (!lastTimestamp && !lastBytesAudio && !lastBytesVideo) {
lastTimestamp = timestamp;
if (audio) lastBytesAudio = audio.rtcpBytesSent;
if (video) lastBytesVideo = video.rtcpBytesSent;
if (audio) lastBytesAudio = audio.bytesSent;
if (video) lastBytesVideo = video.bytesSent;
return;
} else {
var timeSince = (timestamp - lastTimestamp) / 1000;
if (audio) {
bpsAudio = (((audio.rtcpBytesSent - lastBytesAudio) / timeSince) / 1000) * 8;
lastBytesAudio = audio.rtcpBytesSent;
bpsAudio = audio.bitrateCalculated / 1000;
lastBytesAudio = audio.bytesSent;
}
if (video) {
bpsVideo = (((video.rtcpBytesSent - lastBytesVideo) / timeSince) / 1000) * 8;
lastBytesVideo = video.rtcpBytesSent;
bpsVideo = video.bitrateCalculated / 1000;
lastBytesVideo = video.bytesSent;
}
if (audio || video) lastTimestamp = timestamp;
}
Expand All @@ -391,14 +391,14 @@ $(document).ready(function(){
if (audio) {
$('#audioSSRC').html(audio.ssrc);
if (bpsAudio != 0) $('#audioBytesSent').html(Math.round(bpsAudio * 100)/100 + " Kbps");
$('#audioPacketsSent').html(audio.rtcpPacketSent);
$('#audioPacketsSent').html(audio.packetsSent);
kbpsAudio = Math.round(bpsAudio * 100)/100;
ssrcs[audio.ssrc] = "audio";
}
if (video) {
$('#videoSSRC').html(video.ssrc);
if (bpsVideo != 0) $('#videoBytesSent').html(Math.round(bpsVideo * 100)/100 + " Kbps");
$('#videoPacketsSent').html(video.rtcpPacketSent);
$('#videoPacketsSent').html(video.packetsSent);
kbpsVideo = Math.round(bpsVideo * 100)/100;
ssrcs[video.ssrc] = "video";
}
Expand Down

0 comments on commit c51d6e3

Please sign in to comment.