问题
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.
回答1:
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 :-)
})
回答2:
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);
}
}
});
来源:https://stackoverflow.com/questions/24066850/is-there-an-api-for-the-chrome-webrtc-internals-variables-in-javascript