Search code examples
webrtccoturn

connection issues webRTC App. works only local, not mobile


Would really appreciate some help on this issue. Have no idea how to continue.

Trying to make a webRTC App. Signaling Server is WebSocket on Node.js. For some reason cannot establish connection with mobile phone. Using - or - trying to use coturn. Im not sure if the problem is clientside, or serverside @ coturn relay server.

the caller is in my case a pc behind a reguler router, callee is mobile phone, turn and websocket are public.

///CLIENTS BOTH CALLER and CALLEE
async function createPeerConnection() {
  log("Setting up a connection...");
  const iceConfig = {
    "iceServers": [{
      "urls": "stun:mycoturn.online:5349",
      "username": "guest",
      "credential": "password"
    }
    ,{
      "urls": "turn:mycoturn.online:5349",
      "username": "guest",
      "credential": "password"
    }]
  }

  myPeerConnection = new RTCPeerConnection(
  // {
  //   iceServers: [    
  //     {
  //       urls: "stun:stun1.l.google.com:19302",
  //       username: "",
  //       credential: ""
  //     }
  //   ]
  // }
   iceConfig
  );

  myPeerConnection.onicecandidate = handleICECandidateEvent;
  myPeerConnection.oniceconnectionstatechange = handleICEConnectionStateChangeEvent;
  myPeerConnection.onicegatheringstatechange = handleICEGatheringStateChangeEvent;
  myPeerConnection.onsignalingstatechange = handleSignalingStateChangeEvent;
  myPeerConnection.onnegotiationneeded = handleNegotiationNeededEvent;
  myPeerConnection.ontrack = handleTrackEvent;
}

[... Some code]

function handleICECandidateEvent(event) {
  // if (event.candidate) {
    log("*** Outgoing ICE candidate: ");
    sendToServer({
      type: "new-ice-candidate",
      target: targetId,
      candidate: event.candidate,
      id: clientID
    });
  // }
}

async function handleNewICECandidateMsg(msg) {
  var candidate = msg.candidate;

  log("*** Adding received ICE candidate: " + JSON.stringify(candidate));
  try {
    await myPeerConnection.addIceCandidate(candidate)
  } catch(err) {
    reportError(err);
  }
}

The last sent candidate from both the caller and callee is null(candidate:null) which is added by both as well addIceCandidate(candidate)

After the callee gets candidateevent "candidate:null" the callee gets "handleICEConnectionStateChangeEvent: failed" finally i get this error msg in console:

ICE failed, your TURN server appears to be broken, see about:webrtc for more details

this is the final and only error-msg which i receive with public google stun Server, as well as with my coturn stun/turn.

Which meaningfull information should i provide? Where should i search for error? Have really no idea.

Many thanks in advance Cheers


Solution

  • First things first.

    You have to check your turn server(coTURN) running well.

    For checking, go to Trickle ICE.

    1. Remove default google stun server, and add your turn server information.

    2. Select relay option at the ICE Options part.

    3. Click 'Gather candidates' button.

    If you can get candidate who has 'rtp relay' component type, your turn server running well.

    Thus if no candidate, you have to fix your turn server.

    if not, you have to fix your signaling server or client.