2015-03-11 22 views
5

ho un app WebRTC, e diciamo due clienti (client1 e client2), c'è qualche modo per scoprire cosa candidato ICE data dal client1 viene utilizzato da client2 e viceversa? perché, ogni volta per trovare questo fuori, devo usare wireshark su entrambi i clienti, ho pensato leggendo il sdp potrebbe aiutare, ma mi sbagliavo, in quanto dà tutti i possibili candidati ...WebRTC: Determinare l'ICE candidato scelto

Scenario: tutto Le porte UDP del client1 sono bloccate (mi blocco per scopi di test).
di Client1 SDP:

... 
a=rtcp:49407 IN IP4 <client1's IP> 
a=candidate:3864409487 1 udp 2122194687 <client1's IP> 49407 typ host generation 0 // this would never work, since the udp ports are blocked... 
a=candidate:3864409487 2 udp 2122194687 <client1's IP> 49407 typ host generation 0 
a=candidate:2832583039 1 tcp 1518214911 <client1's IP> 0 typ host tcptype active generation 0 
a=candidate:2832583039 2 tcp 1518214911 <client1's IP> 0 typ host tcptype active generation 0 
a=candidate:973648460 1 udp 25042687 <TURN server IP> 64790 typ relay raddr <Proxy IP> rport 39963 generation 0 
a=ice-ufrag:YSvrOiav8TglpCWD 
... 
+3

Partenza questa discussione: https://groups.google.com/d/msg/discuss-webrtc/-VReEXf9RBM/h91i7CD-oJ8 J –

risposta

3

Ebbene, preso dal mio answer ad un'altra domanda

ho scritto e testato il pezzo di sotto del codice, funziona in tutte le versioni di Firefox e Chrome, getConnectionDetails restituisce un promessa che risolve a dettagli di connessione:

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 
    return peerConnection.getStats(null).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; 
    }); 

    } 
} 


//usage example: 
getConnectionDetails(pc).then(console.log.bind(console)); 
+0

Ho ottenuto '' 'prflx''' per' '' googRemoteCandidateType''' e '' 'relay''' per' '' googLocalCandidateType'''. Sai cosa '' '' prflx''' significa ?? –

+0

@e devo controllare, ma penso che sia il candidato stordente – mido