p2p-media-loader icon indicating copy to clipboard operation
p2p-media-loader copied to clipboard

[Contributions] Show bandwidth Savings Percentage in colse

Open marcofbb opened this issue 3 years ago • 1 comments

This code shows you the percentage of bandwidth savings per browser console

image

/** 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);

marcofbb avatar Jul 24 '20 16:07 marcofbb

It will be better to use Math.round round up the result

hklcf avatar Nov 20 '20 15:11 hklcf