2014-01-08 13 views
1

我目前正在研究webrtc會話的監控工具,調查從調用者到被調用者的調用SDP,反之亦然。不幸的是,我無法確定哪個ip流被真正使用,因爲每個會話建立> 10個候選行,並且在某些候選被推入個人計算機之後以某種方式建立會話。WebRTC Peerconnection:使用哪個IP流程的候選集?

是否有任何方法可以找出哪些流程正在使用候選流程集?

回答

0

我想知道同樣的事情,所以寫了一個小funtion它返回解析爲候選人承諾詳細信息:

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

    } 
}