webRTC Coturn server return null iceCandidate?

213 Views Asked by At

I installed coturn server on an Ubuntu VPS for testing purposes, the testing of the coturn server on Trickle ICE looks great and everything is fine, but when I try to make a connection it returns null iceCandidate when peers are from different networks and it works fine when peers are in the same local network.

This is my Trickle ICE test results:

Trickle ICE test results

This is what I get when console logging the iceCandidate:

iceCandidates

And this is my iceservers:

const iceServers = {
iceServer: [
  {
   urls: "stun:stun.biodietfood.com:3478",
  },
  {
   urls: "turn:turn.biodietfood.com:3478?transport=tcp",
   username: "myuser",
   credential: "mypassword",
  },
 ],
};

And this is my code to make peer connection and sending an offer:

rtcPeerConnection = new RTCPeerConnection(); //create peer connection
rtcPeerConnection.setConfiguration(iceServers);
rtcPeerConnection.onicecandidate = onIceCandidate; //generate ice candidate
rtcPeerConnection.onicecandidateerror = iceCandidateError;
rtcPeerConnection.ontrack = onAddStream; // generate the remote stream to send to other user
rtcPeerConnection.addTrack(localStream.getTracks()[0], localStream); // adding video
rtcPeerConnection.addTrack(localStream.getTracks()[1], localStream); // adding audio
rtcPeerConnection // creating offer
  .createOffer({ iceRestart: true })
  .then((sessionDescription) => {
    rtcPeerConnection.setLocalDescription(sessionDescription);
    socket.emit("offer", {
      type: "offer",
      sdp: sessionDescription,
      room: roomNumber,
    });
  })
  .catch((err) => {
    console.log(err);
  });

The same code is used for creating an answer with little modifications.

How can I solve the problem?

0

There are 0 best solutions below