0

I want to make voice calling with nodejs and webrtc.When I call to other user then getting error'ICE failed, see about:webrtc for more details'. The HTML just contains a button that calls offer().

I can confirm the offer and SessionDescriptions are transferring successfully from one client to the other. Please help me

 Client Side Javasrcipt: 
    navigator.getUserMedia({video:false, audio:true}, function(stream)                 {
document.getElementById("localvideo").mozSrcObject = stream;
document.getElementById("localvideo").play();
document.getElementById("localvideo").muted = true;

// var pc = new mozRTCPeerConnection();
var pc = new PeerConnection(iceServers, options);
pc.addStream(stream);

pc.onaddstream = function(obj) {
log("Got onaddstream of type " + obj.type);
document.getElementById("remotevideo").mozSrcObject = obj.stream;
document.getElementById("remotevideo").play();
document.getElementById("dialing").style.display = "none";
document.getElementById("hangup").style.display = "block";
};

pc.createOffer(function(offer) {
console.log("Created offer" + JSON.stringify(offer));
pc.setLocalDescription(offer, function() {
// Send offer to remote end.       
pc.iceCandidate = new RTCIceCandidate();      
console.log(pc.iceCandidate);
    peerc = pc;
    jQuery.post(
      "offer", {
        to: user,
        from: document.getElementById("user").innerHTML,
        offer: JSON.stringify(offer)
      },
      function() { console.log("Offer sent!"); }
    ).error(error);
  }, error);
}, error);

});

And my Server Side script-

        app.post("/offer", function(req, res) { 
          var channel = users[req.body.to];
           channel.write("event: offer\n");
          channel.write("data: " + JSON.stringify(req.body));
          channel.write("\n\n");
          res.send(200);
        });
mido
  • 24,198
  • 15
  • 92
  • 117
Pardeep Beniwal
  • 63
  • 2
  • 10

3 Answers3

3

I am not which is the case here, either you have not provided compelete app code or your app code for proper webrtc connection is incomplete,

For starters, as much as webrtc has simplified video chat, simply sending the offer sdp would not do the trick( I am assuming that you created answer sdp on the other side and sending it), you are going to have to exchange ICE candidates also. As peer's ice candidates are sort of like their calling card tells how they can be reached. So without excahnging them, they cannot communticate.

enter image description here

generally, the browser provides you the ice candidate in onIceCandidate event, this you send to your peer, which would add it as peerConnection.addIceCandidate(candidate), initially when I started out, this doc truly helped me in understanding the basics of WebRTC, you could give it a try.

mido
  • 24,198
  • 15
  • 92
  • 117
1

You need to add the receiving end and handle ICE candidates. I see createOffer but not createAnswer, and the ICE failures are probably from not signaling ICE candidates across (a practice called Trickle ICE, which is required now).

It looks like you're using Firefox, so you should be able to run this local-loop demo (no signaling), which I still hope points out the missing pieces to close the loop. I use video because audio works terribly in local-loops for obvious reasons (feedback):

var pc1 = new mozRTCPeerConnection(), pc2 = new mozRTCPeerConnection();

pc1.onicecandidate = e => !e.candidate ||
    pc2.addIceCandidate(e.candidate).catch(failed);
pc2.onicecandidate = e => !e.candidate ||
    pc1.addIceCandidate(e.candidate).catch(failed);
pc2.onaddstream = e => v2.mozSrcObject = e.stream;

function start() {
  navigator.mediaDevices.getUserMedia({ video: true })
  .then(stream => pc1.addStream(v1.mozSrcObject = stream))
  .then(() => pc1.createOffer())
  .then(offer => pc1.setLocalDescription(offer))
  .then(() => pc2.setRemoteDescription(pc1.localDescription))
  .then(() => pc2.createAnswer())
  .then(answer => pc2.setLocalDescription(answer))
  .then(() => pc1.setRemoteDescription(pc2.localDescription))
  .then(() => log("Connected!"))
  .catch(failed);
}

var log = msg => div.innerHTML += "<p>" + msg + "</p>";
var failed = e => log(e +", line "+ e.lineNumber);
<video id="v1" height="120" width="160" autoplay></video>
<video id="v2" height="120" width="160" autoplay></video><br>
<button onclick="start()">Start!</button><div id="div"></div>
jib
  • 40,579
  • 17
  • 100
  • 158
  • Now I have add icecandidate and getting error-- ' ICE failed, see about:webrtc for more details' . You can see my server side file http://pastebin.com/vgDikg5k and client side http://pastebin.com/2Au9H2j5 – Pardeep Beniwal Jul 17 '15 at 10:57
0

Are you generating answer on the other end and sending it back to first party to process it?

JDT
  • 109
  • 1
  • 2
  • 10
  • I have done that now error getting ' ICE failed, see about:webrtc for more details' . You can see my server side file http://pastebin.com/vgDikg5k and client side http://pastebin.com/2Au9H2j5 – Pardeep Beniwal Jul 17 '15 at 10:53
  • Don't create different PeerConnections in response to ICE messages. ICE candidates are guaranteed not to be generated before the `setLocalDescription` success-callback has been called, and remotely need to go to the same PeerConnection that received the offer. E.g. on the signaling channel you'll see: `offer, candidate, candidate`, never `candidate, offer, candidate`, if that makes sense. Also make sure you attach `onicecandidate` to the connection you're actually using, e.g. from `initiateCall`. – jib Jul 17 '15 at 14:12
  • You might also want to look at using [adapter.js](https://github.com/webrtc/adapter) to take care of polyfilling the browser differences (there are still quite a few). – jib Jul 17 '15 at 14:15