getStats.js
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.
It is MIT Licenced, which means that you can use it in any commercial/non-commercial product, free of cost.
npm install getstats
To use it:
<script src="./node_modules/getstats/getStats.js"></script>
Link the library
<script src="//cdn.webrtc-experiment.com/getStats.js"></script>
First Step
// if your code is encapsulated under a method
(function() {
RTCPeerConnection.prototype.getStats = window.getStats;
})();
// otherwise skip first step
Last Step
var rtcPeerConnection = new RTCPeerConnection(iceServers);
var repeatInterval = 2000; // 2000 ms == 2 seconds
rtcPeerConnection.getStats(function(result) {
result.connectionType.remote.ipAddress
result.connectionType.remote.candidateType
result.connectionType.transport
result.audio.availableBandwidth
result.audio.packetsSent
result.audio.packetsLost
result.audio.rtt
// to access native "results" array
result.results.forEach(function(r) {
console.log(r);
});
}, repeatInterval);
result.audio
- availableBandwidth
- inputLevel
- packetsLost
- rtt
- packetsSent
- bytesSent
result.video
- availableBandwidth
- googFrameHeightInput
- googFrameWidthInput
- googCaptureQueueDelayMsPerS
- rtt
- packetsLost
- packetsSent
- googEncodeUsagePercent
- googCpuLimitedResolution
- googNacksReceived
- googFrameRateInput
- googPlisReceived
- googViewLimitedResolution
- googCaptureJitterMs
- googAvgEncodeMs
- googFrameHeightSent
- googFrameRateSent
- googBandwidthLimitedResolution
- googFrameWidthSent
- googFirsReceived
- bytesSent
result.connectionType
- local.candidateType
- local.ipAddress
- remote.candidateType
- remote.ipAddress
- transport
result.results
It is an array that is returned by browser's native PeerConnection API.
Credits
- Personal Webpage: http://www.muazkhan.com
- Email: muazkh@gmail.com
- Twitter: https://twitter.com/muazkh and https://twitter.com/WebRTCWeb
- Google+: https://plus.google.com/+WebRTC-Experiment
- Facebook: https://www.facebook.com/WebRTC
License
getStats.js is released under MIT licence . Copyright (c) Muaz Khan.