3

注意:请检查最近的编辑

我在边缘收到此警告:

Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification

我不明白如何解决这个问题。我使用了一个adapter.js,我发现了一个人们谈论这个问题的线程。但修复不起作用。

我试图添加pc.addIceCandidate(null),但它什么也没做。


在 chrome 上它可以工作,ICE 状态从checkingconnected非常快。

在边缘,ICE 状态保持不变,checking几秒钟后进入new,但它不应该是新的。

编辑:

添加pc.addIceCandidate(null);给了我0: InvalidStateError。我打电话之前的状态pc.addIceCandidate(null);new.

我也尝试过使用pc.addIceCandidate({candidate:''});,但它什么也没做。

以下是代码的相关部分,我尝试在其中添加修复:

function handleIceCandidate(event) {
  console.log('icecandidate event: ', event);
  if (event.candidate) {
    sendMessage([{
      type: 'candidate',
      label: event.candidate.sdpMLineIndex,
      id: event.candidate.sdpMid,
      candidate: event.candidate.candidate
    }, room]);
  } else {
    console.log("state in End of candidates: " + pc.iceConnectionState);
    if (window.navigator.userAgent.indexOf("Edge") > -1 && pc.iceConnectionState == "new") {
      //pc.addIceCandidate(null);
      pc.addIceCandidate({candidate:''});
    }
  }
}

在套接字调用中:

socket.on('message', function(message) {


  if (message.type === 'candidate' && isStarted) {

    var candidate = new RTCIceCandidate({
      sdpMLineIndex: message.label,
      candidate: message.candidate
    });
    pc.addIceCandidate(candidate);
    console.log("state in socket: " + pc.iceConnectionState);
    if (window.navigator.userAgent.indexOf("Edge") > -1 && pc.iceConnectionState == "new") {
      //pc.addIceCandidate(null);
      pc.addIceCandidate({candidate:''});
    }
  } 
});

编辑:

看起来有一个问题adapter.js

if (!pc._remoteDescription) {
        return reject(makeError('InvalidStateError',
            'Can not add ICE candidate without a remote description'));
      } else if (!candidate || candidate.candidate === '') { 
        for (var j = 0; j < pc.transceivers.length; j++) {
          if (pc.transceivers[j].rejected) {
            continue;
          }
          pc.transceivers[j].iceTransport.addRemoteCandidate({});
          sections = SDPUtils.getMediaSections(pc._remoteDescription.sdp);
          sections[j] += 'a=end-of-candidates\r\n';
          console.log("tries to send end of candidates (I added this)");
          pc._remoteDescription.sdp =
              SDPUtils.getDescription(pc._remoteDescription.sdp) +
              sections.join('');
          if (pc.usingBundle) {
            break;
          }
        }
      }

它应该进入else if,但它永远不会这样做。我试过了console.log(candidate.candidate),它告诉我undefined。我尝试添加 || candidate.candidate == undefined到 else if 条件,但它仍然不会进入else if.

其实修改adapter.js文件感觉已经不对了。我还验证了我使用的是最新版本,我不知道这里发生了什么以及为什么我似乎是唯一一个遇到这个问题的人。

编辑:

我有atm的最好方法。pc.addIceCandidate(null)仅在此处使用:

function handleIceCandidate(event) {
  console.log('icecandidate event: ', event);
  if (event.candidate) {
    sendMessage([{
      type: 'candidate',
      label: event.candidate.sdpMLineIndex,
      id: event.candidate.sdpMid,
      candidate: event.candidate.candidate
    }, room]);
  } else {
    if (window.navigator.userAgent.indexOf("Edge") > -1) {
      pc.addIceCandidate(null);
    }
  }
}

这将进入else if尝试附加的adapter.js中a=end-of-candidates\r\n,但之前失败了:

0: InvalidAccessError

它在adapter.js中的这一行:

pc.transceivers[j].iceTransport.addRemoteCandidate({});

我想我需要在null这里添加候选人,我尝试了不同的语法变体,但没有成功:

pc.transceivers[j].iceTransport.addRemoteCandidate(null);
pc.transceivers[j].iceTransport.addRemoteCandidate({candidate:''});
pc.transceivers[j].iceTransport.addRemoteCandidate();
pc.transceivers[j].iceTransport.addRemoteCandidate({""});

来自Edge 上的Microsoft Docu :

当远程 RTCIceGathereremits 其最终候选者时,应使用 RTCIceCandidateComplete 字典作为参数调用 addRemoteCandidate(),以便本地 RTCIceTransport 可以知道没有更多预期的远程候选者,并且可以进入“完成”状态。

我试过了:

pc.transceivers[j].iceTransport.addRemoteCandidate(new RTCIceCandidateComplete({complete:true}));
pc.transceivers[j].iceTransport.addRemoteCandidate({complete:true});

第一个给我:

RTCIceCandidateComplete is not defined
4

0 回答 0