简体   繁体   English

使WebRTC正常运行(如何调试ICE失败?)

[英]Getting WebRTC working (how to debug ICE Fail?)

I can't figure out how to debug WebRTC. 我不知道如何调试WebRTC。 I keep getting 'ICE Failed' errors, but I doubt that's the issue. 我不断收到“ ICE Failed”错误,但我怀疑那是问题所在。 Here's my code: https://github.com/wamoyo/webrtc-cafe/tree/master/2.1%20Establishing%20a%20Connection%20%28within%20a%20Local%20Area%20Network%29 这是我的代码: https : //github.com/wamoyo/webrtc-cafe/tree/master/2.1%20 Establishmenting%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. 我正在使用node.js / express / socket.io设置房间并连接对等节点,然后使用一些默认的公共服务器进行信号传输。

The strange thing is, it appears the I have the remoteStream on the client. 奇怪的是,它似乎在客户端上有remoteStream。

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): 这是我遇到的两个错误(顺便说一下,现在,我只是尝试将手机连接到笔记本电脑或两个浏览器选项卡,所有这些都在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: 首先,您应该以与本地视频流相同的方式设置remoteVideo.src URL参数:

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 . 其次,你应该通过一个约束对象到createOffer()createAnswer()方法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候选人。 ICE candidates can be part of the offer/answer SDP, but not always. ICE候选人可以成为要约/答案SDP的一部分,但并非总是如此。 To ensure that you send all of them, you should implement an onicecandidate handler on the RTCPeerConnection : 为了确保您发送所有的人,你应该实现一个onicecandidate在处理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 您将必须在server.js中的客户端之间实现“候选冰”消息中继

Hope this helps, and good luck! 希望这会有所帮助,并祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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