Is there an API for the chrome://webrtc-internals/ variables in javascript?

Marco Pashkov picture Marco Pashkov · Jun 5, 2014 · Viewed 7.1k times · Source

I want to get access to some of the logged variables in the chrome://webrtc-internals/, but I didn't find anything on google - not even a description of the graphs I can see.
I am particularly interested in packetsLost, googCurrentDelayMs and googNacksSent.

why I want to access the webrtc-internals
I am writing a google chrome application that shares a video stream (p2p). It uses peerjs to share the stream with other peers, which in turn uses googles webrtc implementation underneath. To make my application perfect I would need to know when a big delay occurs. Since I can see the delay logged in chrome://webrtc-internals/ I was wondering if I could access it through javascript.

My guess is there is no API for the chrome://webrtc-internals/-menu.

Answer

Marco Pashkov picture Marco Pashkov · Jun 5, 2014

I found it - had to crawl through a couple of google community-threads(thread 1, thread2):

var peerjs = new Peer(...);  // initialize peerJS
var connections = peerjs.connections;

Connections is an object:

Object {2e1c5694-e6ef-e1b2-22d5-84a3807961d4: Array[3]}
    2e1c5694-e6ef-e1b2-22d5-84a3807961d4: Array[3]
        0: DataConnection
        1: MediaConnection
        2: MediaConnection
        length: 3
    __proto__: Array[0]
__proto__: Object

Take a look at any of those connection objects:

var rtcPeerConn = connectionObject.pc; // RTCPeerConnection

rtcPeerConn.getStats(function callback(connStats){
    var rtcStatsReports = connStats.result() // array of available status-reports
    // each status-report object has many status variables, such as
    // googCurrentDelayMs. You need to iterate over all object and check 
    // their names to find the one status report you want
    rtcStatsReports[7].names() // returns all available variables for that report

    var googCurrentDelayMs = rtcStatsReports[7].stat('googCurrentDelayMs')
    console.log(googCurrentDelayMs) // finally - googCurrentDelayMs :-)
})