我正在尝试在两台pc之间进行视频通话,我不想使用冰滴,有时我可以进行视频通话,其他时候(我不知道为什么)我无法收集所有的冰候选人,iceGatheringState停留在聚集状态,永远不会完成。
我已经尝试使用事件onicecandidate并等待null候选。现在我使用的是onIceGatheringStateChange。
pc=new RTCPeerConnection(iceServers);
pc.onicegatheringstatechange=function(){
if(pc.iceGatheringState=='complete'){
send_to_target(pc.localDescription);
}
}
localStream.getTracks().forEach(track=>pc.addTrack(track,localStream));
pc.createOffer().then(function(sessionDescription){
pc.setLocalDescription(sessionDescription);
})我正在用chrome在两台笔记本电脑上测试这一点,我希望iceGatheringState进入完成状态,或者知道另一种方法/条件来收集冰候选,以便在不使用冰滴流的情况下将sessionDescription发送到目标。
谢谢。
发布于 2021-08-16 03:15:34
据我所知,有两种方法可以确定"ICE候选人聚集“/ "ICE滴流”何时完成。
let pc = new RTCPeerConnection();
pc.onicegatheringstatechange = ev => {
let connection = ev.target;
switch(connection.iceGatheringState) {
case "gathering":
/* collection of candidates has begun */
break;
case "complete":
/* collection of candidates is finished */
break;
}
}let pc = new RTCPeerConnection();
pc.onicecandidate = function(event) {
if (event.candidate) {
/* Code for each candidate */
/* Send the candidate to the remote peer */
} else {
/* All ICE candidates have been sent */
}
}WebRTC的帮助链接:
https://stackoverflow.com/questions/56085742
复制相似问题