title: WebRTC: How to calculate user bandwidth/network latency of RTC Peer Connection
body: <p>So, I'm working on an App that utilises WebRTC to provide video/audio communication between peers.</p>
  
  <p>I'd like to provide some feedback to users in regard to their network connection/bandwidth/latency etc in order to suggest possible solutions if bandwidth etc is terrible. </p>
  
  <p>WebRTC has a <a href="https://www.w3.org/TR/webrtc-stats/" rel="nofollow"><code>getStats()</code></a> API which provides a number of key pieces of information. When a Peer Connection is active, <code>getStats()</code> gives me the following object...</p>
  
  <pre><code>{
      "googLibjingleSession_5531731670954573009":{
          "id":"googLibjingleSession_5531731670954573009",
          "timestamp":"2016-02-02T11:14:43.467Z",
          "type":"googLibjingleSession",
          "googInitiator":"true"
      },
      "googTrack_SCEHhCOl":{
          "id":"googTrack_SCEHhCOl",
          "timestamp":"2016-02-02T11:14:43.467Z",
          "type":"googTrack",
          "googTrackId":"SCEHhCOl"
      },
      "ssrc_360347109_recv":{
          "id":"ssrc_360347109_recv",
          "timestamp":"2016-02-02T11:14:43.467Z",
          "type":"ssrc",
          "googDecodingCTN":"757",
          "packetsLost":"0",
          "googSecondaryDecodedRate":"0",
          "googDecodingPLC":"3",
          "packetsReceived":"373",
          "googExpandRate":"0.00579834",
          "googJitterReceived":"0",
          "googDecodingCNG":"0",
          "ssrc":"360347109",
          "googPreferredJitterBufferMs":"20",
          "googSpeechExpandRate":"0.00140381",
          "googTrackId":"SCEHhCOl",
          "transportId":"Channel-audio-1",
          "googDecodingPLCCNG":"10",
          "googCodecName":"opus",
          "googDecodingNormal":"744",
          "audioOutputLevel":"6271",
          "googAccelerateRate":"0",
          "bytesReceived":"21796",
          "googCurrentDelayMs":"64",
          "googDecodingCTSG":"0",
          "googCaptureStartNtpTimeMs":"-1",
          "googPreemptiveExpandRate":"0.00292969",
          "googJitterBufferMs":"42"
      }
  }
  </code></pre>
  
  <p>It's with this information that I hope to calculate the users...</p>
  
  <p>a) Bandwidth (Ideally Audio and Video separately but straight up bandwidth would suffice)</p>
  
  <p>b) Network Latency</p>
  
  <p>Thanks in advance...</p>
  
  <p><strong>NB</strong>: I have already seen <a href="https://github.com/muaz-khan/getStats/blob/master/getStats.js" rel="nofollow">this wrapper</a> but I'd like to be able to do this myself really (with a little bit of your help of course :D) as the example code for this wrapper uses a "bytesSent" property which I don't seem to get back from <code>getStats()</code>?</p>
  
  <p>I am also aware of the <a href="https://test.webrtc.org/" rel="nofollow">WebRTC test</a> available on GitHub, but again, I should be able to achieve what I want without relying on third party "plugins" etc.</p>