1

私は現在、呼び出し元から呼び出し先へ、またはその逆に転送された SDP を調査する webrtc セッションの監視ツールに取り組んでいます。残念ながら、セッション確立ごとに 10 を超える候補行があり、一部の候補が PC 内にプッシュされた後にセッションが確立されるため、実際に使用されている IP フローを特定できません。

一連の候補フローのうち、どのフローが使用されているかを把握する方法はありますか?

4

2 に答える 2

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 に答える