WebRTC error - RTCPeerConnection.connectionState failed

2.3k views Asked by At

I have a problem with a video call project I created. I followed the steps in this video https://www.youtube.com/watch?v=_3exOT53faw&ab_channel=CodeShell, but I get an error because RTCPeerConnection.connectionState is failed. According to https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/connectionState it is because "One or more of the ICE transports on the connection is in the failed state.". I don't know if I should change the servers I use, or add new ones. Any ideas? Here is part of the code:

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());
  });
2

There are 2 answers

0
Oahid Zihad On
"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",

use these ice Servers... Hope it will work.....

0
Giang Phong On

The problem may be you are behind the symetric NAT, connectionState change to failed after 30s from time you start checking connection state and if no candidate pair valid found (pingable). Use TURN server (for relay) may help you