1

我目前正在开发一个用于 webrtc 会话的监视工具,以调查从调用者到被调用者的传输 SDP,反之亦然。不幸的是,我无法弄清楚真正使用了哪个 ip 流,因为每个会话建立有 >10 个候选行,并且在某些候选被推入 PC 后以某种方式建立了会话。

有什么方法可以确定候选流程集中使用了哪个流程?

4

2 回答 2

1

我自己解决了这个问题!:)

有一个函数叫做 peerConnection.getStats(callback);

这将提供正在进行的对等连接的大量信息。

再见

于 2014-01-10T14:27:42.707 回答
0

我想找出同样的事情,所以写了一个小函数,它返回一个可以解析候选细节的承诺:

function getConnectionDetails(peerConnection){


  var connectionDetails = {};   // the final result object.

  if(window.chrome){  // checking if chrome

    var reqFields = [   'googLocalAddress',
                        'googLocalCandidateType',   
                        'googRemoteAddress',
                        'googRemoteCandidateType'
                    ];
    return new Promise(function(resolve, reject){
      peerConnection.getStats(function(stats){
        var filtered = stats.result().filter(function(e){return e.id.indexOf('Conn-audio')==0 && e.stat('googActiveConnection')=='true'})[0];
        if(!filtered) return reject('Something is wrong...');
        reqFields.forEach(function(e){connectionDetails[e.replace('goog', '')] = filtered.stat(e)});
        resolve(connectionDetails);
      });
    });

  }else{  // assuming it is firefox
    var stream = peerConnection.getLocalStreams()[0];
    if(!stream || !stream.getTracks()[0]) stream = peerConnection.getRemoteStreams()[0];
    if(!stream) Promise.reject('no stream found')
    var track = stream.getTracks()[0];
    if(!track)  Promise.reject('No Media Tracks Found');
    return peerConnection.getStats(track).then(function(stats){
        var selectedCandidatePair = stats[Object.keys(stats).filter(function(key){return stats[key].selected})[0]]
          , localICE = stats[selectedCandidatePair.localCandidateId]
          , remoteICE = stats[selectedCandidatePair.remoteCandidateId];
        connectionDetails.LocalAddress = [localICE.ipAddress, localICE.portNumber].join(':');
        connectionDetails.RemoteAddress = [remoteICE.ipAddress, remoteICE.portNumber].join(':');
        connectionDetails.LocalCandidateType = localICE.candidateType;
        connectionDetails.RemoteCandidateType = remoteICE.candidateType;
        return connectionDetails;
    });

  }
}
于 2015-08-21T09:43:02.283 回答