p2p-media-loader
p2p-media-loader copied to clipboard
[Contributions] Show bandwidth Savings Percentage in colse
This code shows you the percentage of bandwidth savings per browser console
/** Bandwidth Savings */
var downloaded_total = 0;
var downloaded = 0;
engine.on('piece_bytes_downloaded', function(method, bytes, peerId) {
if(peerId){
downloaded += bytes;
}
downloaded_total += bytes;
});
setInterval(function(){ console.log("Bandwidth Savings: " + ((downloaded*100)/downloaded_total) + "%"); }, 5000);
It will be better to use Math.round
round up the result