Code Monkey home page Code Monkey logo

getstats's Introduction

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>

window.getStats

To invoke directly:

getStats(peer, callback, interval);

RTCPeerConnection.prototype.getPeerStats

Or, to setup an instance method:

// if your code is encapsulated under a method
(function() {
    RTCPeerConnection.prototype.getPeerStats = window.getStats;
    
    // or
    RTCPeerConnection.prototype.__getStats = window.getStats;
    
    // or
    RTCPeerConnection.prototype.getConnectionStats = window.getStats;
    
    // or
    RTCPeerConnection.prototype['your-choice'] = window.getStats;
})();

NEVER set/override RTCPeerConnection.prototype.getStats because it is a reserved method.

// following will fail
RTCPeerConnection.prototype.getStats = window.getStats;

// it should be
RTCPeerConnection.prototype.intanceMethodNamae = window.getStats;

Usage

var rtcPeerConnection = new RTCPeerConnection(iceServers);

var repeatInterval = 2000; // 2000 ms == 2 seconds
rtcPeerConnection.getPeerStats(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);

Firefox?

peer.getStats(peer.getLocalStreams()[0].getAudioTracks()[0], function(results) {
    // rest goes here
}, 5 * 1000);

result.audio

  1. availableBandwidth
  2. inputLevel
  3. packetsLost
  4. rtt
  5. packetsSent
  6. bytesSent

result.video

  1. availableBandwidth
  2. googFrameHeightInput
  3. googFrameWidthInput
  4. googCaptureQueueDelayMsPerS
  5. rtt
  6. packetsLost
  7. packetsSent
  8. googEncodeUsagePercent
  9. googCpuLimitedResolution
  10. googNacksReceived
  11. googFrameRateInput
  12. googPlisReceived
  13. googViewLimitedResolution
  14. googCaptureJitterMs
  15. googAvgEncodeMs
  16. googFrameHeightSent
  17. googFrameRateSent
  18. googBandwidthLimitedResolution
  19. googFrameWidthSent
  20. googFirsReceived
  21. bytesSent

result.connectionType

  1. local.candidateType
  2. local.ipAddress
  3. remote.candidateType
  4. remote.ipAddress
  5. transport

result.results

It is an array that is returned by browser's native PeerConnection API.

Credits

Muaz Khan:

  1. Personal Webpage: http://www.muazkhan.com
  2. Email: [email protected]
  3. Twitter: https://twitter.com/muazkh and https://twitter.com/WebRTCWeb
  4. Google+: https://plus.google.com/+WebRTC-Experiment
  5. Facebook: https://www.facebook.com/WebRTC

License

getStats.js is released under MIT licence . Copyright (c) Muaz Khan.

getstats's People

Contributors

muaz-khan avatar

Watchers

James Cloos avatar James B Gledhill avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.