简体   繁体   中英

Getting WebRTC working (how to debug ICE Fail?)

I can't figure out how to debug WebRTC. I keep getting 'ICE Failed' errors, but I doubt that's the issue. Here's my code: https://github.com/wamoyo/webrtc-cafe/tree/master/2.1%20Establishing%20a%20Connection%20%28within%20a%20Local%20Area%20Network%29

I'm using node.js/express/socket.io for setting up rooms and connecting peers, and then some default public servers for signalling.

The strange thing is, it appears the I have the remoteStream on the client.

Here's the two errors I'm getting (By they way, for now, I'm just trying to connect form my phone to laptop or two browser tabs, all within a LAN):

HTTP "Content-Type" of "text/html" is not supported. Load of media resource http://192.168.1.2:3000/%5Bobject%20MediaStream%5D failed.

ICE failed, see about:webrtc for more details

Any help would rock!

I've made a few comments already, but I think it's also worthwhile to write an answer.

There are 3 big things I see after my first quick read of your code. I haven't tried to actually run or debug your code beyond a superficial reading.

First, you should set the remoteVideo.src URL parameter in the same way as you do the local video stream:

pc.onaddstream = function(media) { // This function runs when the remote stream is added.
    console.log(media);
    remoteVideo.src = window.URL.createObjectURL(media.stream);
}

Second, you should pass a constraints object to the createOffer() and createAnswer() methods of RTCPeerConnection . The constraints should/could look like this:

var constraints = {
    mandatory: {
        OfferToReceiveAudio: true,
        OfferToReceiveVideo: true
    }
};

And you pass this after the success and error callback arguments:

pc.createOffer(..., ..., constraints);

and:

pc.createAnswer(..., ..., constraints);

Lastly, you are not exchanging ICE candidates between your peers. ICE candidates can be part of the offer/answer SDP, but not always. To ensure that you send all of them, you should implement an onicecandidate handler on the RTCPeerConnection :

pc.onicecandidate = function (event) {
    if (event.candidate) {
        socket.emit("ice candidate", event.candidate);
    }
}

You will have to implement "ice candidate" message relaying between clients in your server.js

Hope this helps, and good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM