WebRTC 错误 - RTCPeerConnection.connectionState 失败

问题描述 投票:0回答:2

我创建的视频通话项目有问题。我按照此视频 https://www.youtube.com/watch?v=_3exOT53faw&ab_channel=CodeShell 中的步骤操作,但收到错误,因为 RTCPeerConnection.connectionState 失败。根据 https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState,这是因为“连接上的一个或多个 ICE 传输处于失败状态。”。我不知道是否应该更改我使用的服务器,或添加新的服务器。有任何想法吗? 这是部分代码:

const configuration = {
  iceServers: [
    {
      urls: [
        'stun:stun1.l.google.com:19302',
        'stun:stun2.l.google.com:19302',
      ],
    },
  ],
  iceCandidatePoolSize: 10,
};
peerConnection = new RTCPeerConnection(configuration);

  peerConnection.addEventListener('icecandidate', event => {
    if (!event.candidate) {
      console.log('Got final candidate!');
      return;
    }
    console.log('Got candidate: ', event.candidate);
    callerCandidatesCollection.add(event.candidate.toJSON());
  });
webrtc turn ice rtcpeerconnection
2个回答
0
投票
"stun:stun1.l.google.com:19302",
"stun:stun2.l.google.com:19302",
"stun:stun.l.google.com:19302",
"stun:stun3.l.google.com:19302",
"stun:stun4.l.google.com:19302",

使用这些冰服务器...希望它能工作.....


0
投票

问题可能是您位于对称 NAT 后面,如果没有找到有效的候选对(可 ping 通),则在您开始检查连接状态 30 秒后,连接状态更改为失败。使用 TURN 服务器(用于中继)可能会帮助你

© www.soinside.com 2019 - 2024. All rights reserved.