WebRTC: ICE Candidate Definition Definition

I have a webrtc application and let two clients say ( client1 and client2 ), is there a way to find out which ICE candidate given client1 is used by client2 and vice versa? because, every time, in order to find out, I should use wireshark for both clients, I thought that reading sdp might help, but I was wrong, because it gives all possible candidates ...

Scenario: all UDP ports of client1 are blocked (blocked for me for testing purposes).
Client1 SDP:

 ... a=rtcp:49407 IN IP4 <client1 IP> a=candidate:3864409487 1 udp 2122194687 <client1 IP> 49407 typ host generation 0 // this would never work, since the udp ports are blocked... a=candidate:3864409487 2 udp 2122194687 <client1 IP> 49407 typ host generation 0 a=candidate:2832583039 1 tcp 1518214911 <client1 IP> 0 typ host tcptype active generation 0 a=candidate:2832583039 2 tcp 1518214911 <client1 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 ... 
+5
source share
1 answer

Ok, taken from my answer to another question

I wrote and tested the code below, it works in recent versions of both firefox and chrome, getConnectionDetails returns a promise that resolves the connection details:

 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)); 
+3
source

Source: https://habr.com/ru/post/1215106/


All Articles