gpt4 book ai didi

javascript - WebRTC:确定所选的 ICE 候选者

转载 作者:数据小太阳 更新时间:2023-10-29 05:18:45 27 4
gpt4 key购买 nike

我有一个 webrtc 应用程序,假设有两个客户端(client1client2),有什么方法可以找出 client1 给出的 ICE 候选者client2 使用,反之亦然?因为,每次找出这个问题,我都必须在两个客户端上使用 wireshark,我认为阅读 sdp 可能会有帮助,但我错了,因为它给出了所有可能的候选人...

场景 client1 的所有UDP 端口都被阻塞(为了测试目的而阻塞了我的我)。
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
...

最佳答案

嗯,取 self 的 answer另一个问题

我编写并测试了以下代码,适用于最新版本的 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));

关于javascript - WebRTC:确定所选的 ICE 候选者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28977679/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com