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

为君一笑 提交于 2019-11-28 20:48:51

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 :-)
})

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);
                    }
                }

            });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!