code: function parseStatsNewAPI (peerConnection,
                                                        prevStats,
                                                        currentStats,
                                                        completion) {
  
        var onStatsError = function onStatsError (error) {
              completion(error);
            },
  
            parseAudioStats = function (result) {
              if (result.type==='outboundrtp') {
                currentStats.audioSentPackets = result.packetsSent;
                currentStats.audioSentPacketsLost = result.packetsLost;
                currentStats.audioSentBytes =  result.bytesSent;
              } else if (result.type==='inboundrtp') {
                currentStats.audioRecvPackets = result.packetsReceived;
                currentStats.audioRecvPacketsLost = result.packetsLost;
                currentStats.audioRecvBytes =  result.bytesReceived;
              }
            },
  
            parseVideoStats = function (result) {
              if (result.type==='outboundrtp') {
                currentStats.videoSentPackets = result.packetsSent;
                currentStats.videoSentPacketsLost = result.packetsLost;
                currentStats.videoSentBytes =  result.bytesSent;
              } else if (result.type==='inboundrtp') {
                currentStats.videoRecvPackets = result.packetsReceived;
                currentStats.videoRecvPacketsLost = result.packetsLost;
                currentStats.videoRecvBytes =  result.bytesReceived;
              }
            };
  
        peerConnection.getStats(null, function(stats) {
  
          for (var key in stats) {
            if (stats.hasOwnProperty(key) &&
              (stats[key].type === 'outboundrtp' || stats[key].type === 'inboundrtp')) {
              var res = stats[key];
  
              if (res.id.indexOf('rtp') !== -1) {
                if (res.id.indexOf('audio') !== -1) {
                  parseAudioStats(res);
                } else if (res.id.indexOf('video') !== -1) {
                  parseVideoStats(res);
                }
              }
            }
          }
  
          completion(null, currentStats);
        }, onStatsError);
      }
docs: / Get Stats using the newer API.