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

后端 未结 2 2151
醉话见心
醉话见心 2020-12-13 21:27

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 gr

相关标签:
2条回答
  • 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 :-)
    })
    
    0 讨论(0)
  • 2020-12-13 22:27

    Afer researching a lot, this is how I managed to get the pc using twilio SDK.

    var rtcPeerConn =Twilio.Device.activeConnection();
    rtcPeerConn.options.mediaStreamFactory.protocol.pc.getStats(function callback(report) {
                    var rtcStatsReports = report.result();
                    for (var i=0; i<rtcStatsReports.length; i++) {
                        var statNames = rtcStatsReports[i].names();
                        // filter the ICE stats
                        if (statNames.indexOf("transportId") > -1) {
                            var logs = "";
                            for (var j=0; j<statNames.length; j++) {
                                var statName = statNames[j];
                                var statValue = rtcStatsReports[i].stat(statName);
                                logs = logs + statName + ": " + statValue + ", ";
                            }
                            console.log(logs);
                        }
                    }
                });
    

    //Calculate errorRate Packetlost / packetsent

    var rtcPeerConn =Twilio.Device.activeConnection();
    rtcPeerConn.options.mediaStreamFactory.protocol.pc.getStats(function callback(report) {
                    var error, pcksent;
                    var rtcStatsReports = report.result();
                    for (var i=0; i<rtcStatsReports.length; i++) {
                        var statNames = rtcStatsReports[i].names();
                        // filter the ICE stats
                        if (statNames.indexOf("packetsSent") > -1) {
                            var logs = "";
                            for (var j=0; j<statNames.length; j++) {
                                var statName = statNames[j];
                                var statValue = rtcStatsReports[i].stat(statName);
                                if(statName=="packetsLost")
                                  error= statValue;
                                if(statName =="packetsSent")
                                  pcksent = statValue;
                                logs = logs +"n:" +statName + ": " + statValue + ", ";
                            }
                            console.log(error/pcksent);
                        }
                    }
    
                });
    
    0 讨论(0)
提交回复
热议问题