Skip to content

Commit

Permalink
Released: getstats@1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Nov 19, 2017
1 parent dbdab26 commit 5c69f5b
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Or link specific build:
* https://github.com/muaz-khan/getStats/releases

```html
<script src="https://github.com/muaz-khan/getStats/releases/download/1.0.5/getStats.js"></script>
<script src="https://github.com/muaz-khan/getStats/releases/download/1.0.6/getStats.js"></script>
```

# `window.getStats`
Expand Down Expand Up @@ -99,7 +99,7 @@ rtcPeerConnection.getPeerStats(function(result) {
result.connectionType.remote.candidateType
result.connectionType.transport

result.bandwidth.availableSendBandwidth // it will be your system bandwidth for STUN connections
result.bandwidth.speed // bandwidth download speed (bytes per second)
result.audio.packetsSent
result.audio.packetsLost
result.audio.rtt
Expand Down Expand Up @@ -150,7 +150,10 @@ btnStopGetStats.onclick = function() {

# `result.bandwidth`

1. `result.bandwidth.availableSendBandwidth`
1. `result.bandwidth.speed` - your system bandwidth download speed (bytes per second)
2. `result.bandwidth.systemBandwidth`
3. `result.bandwidth.sentPerSecond`
4. `result.bandwidth.encodedPerSecond`

# `result.audio`

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "getstats",
"description": "A tiny JavaScript library using WebRTC getStats API to return peer connection stats i.e. bandwidth usage, packets lost, local/remote ip addresses and ports, type of connection etc.",
"version": "1.0.5",
"version": "1.0.6",
"authors": [
{
"name": "Muaz Khan",
Expand Down
6 changes: 6 additions & 0 deletions dev/getStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function getStatsLooper() {
// allow users to access native results
getStatsResult.results = results;

if (getStatsResult.audio && getStatsResult.video) {
getStatsResult.bandwidth.speed = (getStatsResult.audio.bytesSent - getStatsResult.bandwidth.helper.audioBytesSent) + (getStatsResult.video.bytesSent - getStatsResult.bandwidth.helper.videoBytesSent);
getStatsResult.bandwidth.helper.audioBytesSent = getStatsResult.audio.bytesSent;
getStatsResult.bandwidth.helper.videoBytesSent = getStatsResult.video.bytesSent;
}

callback(getStatsResult);

// second argument checks to see, if target-user is still connected.
Expand Down
7 changes: 6 additions & 1 deletion dev/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ var getStatsResult = {
bandwidth: {
systemBandwidth: 0,
sentPerSecond: 0,
encodedPerSecond: 0
encodedPerSecond: 0,
helper: {
audioBytesSent: 0,
videoBytestSent: 0
},
speed: 0
},
results: {},
connectionType: {
Expand Down
17 changes: 14 additions & 3 deletions getStats.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

// Last time updated: 2017-08-26 5:42:35 AM UTC
// Last time updated: 2017-11-19 4:49:44 AM UTC

// _______________
// getStats v1.0.4
// getStats v1.0.6

// Open-Sourced: https://github.com/muaz-khan/getStats

Expand Down Expand Up @@ -59,7 +59,12 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
bandwidth: {
systemBandwidth: 0,
sentPerSecond: 0,
encodedPerSecond: 0
encodedPerSecond: 0,
helper: {
audioBytesSent: 0,
videoBytestSent: 0
},
speed: 0
},
results: {},
connectionType: {
Expand Down Expand Up @@ -165,6 +170,12 @@ window.getStats = function(mediaStreamTrack, callback, interval) {
// allow users to access native results
getStatsResult.results = results;

if (getStatsResult.audio && getStatsResult.video) {
getStatsResult.bandwidth.speed = (getStatsResult.audio.bytesSent - getStatsResult.bandwidth.helper.audioBytesSent) + (getStatsResult.video.bytesSent - getStatsResult.bandwidth.helper.videoBytesSent);
getStatsResult.bandwidth.helper.audioBytesSent = getStatsResult.audio.bytesSent;
getStatsResult.bandwidth.helper.videoBytesSent = getStatsResult.video.bytesSent;
}

callback(getStatsResult);

// second argument checks to see, if target-user is still connected.
Expand Down
6 changes: 3 additions & 3 deletions getStats.min.js

Large diffs are not rendered by default.

23 changes: 7 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,7 @@ <h1>
document.getElementById('peer' + peer.id + '-codecsSend').innerHTML = result.audio.send.codecs.concat(result.video.send.codecs).join(', ');
document.getElementById('peer' + peer.id + '-codecsRecv').innerHTML = result.audio.recv.codecs.concat(result.video.recv.codecs).join(', ');

var bandwidthSpeed = bytesToSize((result.audio.bytesSent - bandwidthSpeedHelper[peer.id].prevAudioBytesSent) + (result.video.bytesSent - bandwidthSpeedHelper[peer.id].prevVideoBytesSent));
bandwidthSpeedHelper[peer.id].prevAudioBytesSent = result.audio.bytesSent;
bandwidthSpeedHelper[peer.id].prevVideoBytesSent = result.video.bytesSent;
document.getElementById('peer' + peer.id + '-bandwidthSpeed').innerHTML = bandwidthSpeed;
document.getElementById('peer' + peer.id + '-bandwidthSpeed').innerHTML = bytesToSize(result.bandwidth.speed);

if (result.ended === true) {
result.nomore();
Expand All @@ -492,24 +489,18 @@ <h1>
window.getStatsResult = result;
}

var bandwidthSpeedHelper = {
1: {
prevAudioBytesSent: 0,
prevVideoBytesSent: 0
},
2: {
prevAudioBytesSent: 0,
prevVideoBytesSent: 0
}
};

function bytesToSize(bytes) {
var k = 1000;
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes === 0) {
if (bytes <= 0) {
return '0 Bytes';
}
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(k)), 10);

if(!sizes[i]) {
return '0 Bytes';
}

return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "getstats",
"preferGlobal": true,
"version": "1.0.5",
"version": "1.0.6",
"author": {
"name": "Muaz Khan",
"email": "muazkh@gmail.com",
Expand Down

0 comments on commit 5c69f5b

Please sign in to comment.