简体   繁体   English

WebRTC:确定所选的ICE候选者

[英]WebRTC: Determine the chosen ICE candidate

I have a webrtc app, and let's say two clients( client1 and client2 ), is there any way to find out what ICE candidate given by client1 is used by client2 and vice versa? 我有一个的WebRTC应用程序,并假设两个客户端( client1client2 ),有没有办法找出给出什么ICE候选client1所使用的client2 ,反之亦然? because, every time to find this out, I have to use wireshark on both the clients, I thought reading the sdp might help, but I was wrong, as it gives all possible candidates... 因为,每次发现这一点,我都必须在客户端使用wireshark ,我认为阅读sdp可能有所帮助,但我错了,因为它给了所有可能的候选人......

Scenario: all UDP ports of client1 are blocked( blocked my me for testing purpose). 场景: client1的所有UDP端口都被阻止(为了测试目的阻止了我)。
Client1's SDP: 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
...

Well, taken from my answer to another question 好吧,从我对另一个问题的回答中提取

I wrote and tested the below piece of code, works in latest versions of both firefox and chrome, getConnectionDetails returns a promise which resolves to connection details: 我编写并测试了以下代码,在firefox和chrome的最新版本中工作, getConnectionDetails返回一个解析为连接细节的promise:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM