【问题标题】:Why my WebRTC code is working without specifying STUN/TURN server url?为什么我的 WebRTC 代码在没有指定 STUN/TURN 服务器 url 的情况下工作?
【发布时间】:2019-09-13 21:01:10
【问题描述】:

我已经能够使用 webrtc 连接对等设备。我心中的问题是 RTCPeerConnection()- 在这里我们传递了 stun/turn url。但是当什么都没有通过时它也可以工作!

我想知道它是否在内部使用 google stun 服务器,如果是,为什么在他们的任何文档中都没有提到它。

peerConnection = new RTCPeerConnection();
    peerConnection.setRemoteDescription(description)
    .then(() => peerConnection.createAnswer())
    .then(sdp => peerConnection.setLocalDescription(sdp))
    .then(function () {
        socket.emit('answer', id, peerConnection.localDescription);
    });
    peerConnection.ontrack = function(event) {
        video.srcObject = event.streams[0];
    };
    peerConnection.onicecandidate = function(event) {
        if (event.candidate) {
            socket.emit('candidate', id, event.candidate);
        }

【问题讨论】:

  • 本地网络中没有 STUN 服务器的情况下将建立连接。
  • 请为答案投票,否则其他用户不会认为是正确答案。永远记住首先投票,然后勾选作为未来问题的正确答案。欢迎来到stackover流程:)

标签: webrtc peer simplewebrtc


【解决方案1】:

1) 本地网络不需要 STUN 服务器。

2) 设备使用 STUN 服务器访问自己的公共地址。 (由于两个设备在不同的网络上,所以不能互相连接,因为他们不知道对方的公共IP地址。如果他们知道对方的公共IP地址,他们可以建立P2P连接)

3) TURN 服务器用作备份服务器。 (当 UDP 打孔不起作用时)。 TURN服务器遍历整个数据,因为无法建立P2P连接。

如果您在本地网络上进行测试,则不需要 STUN 服务器。

要使用 STUN 服务器,您需要指定 IP 地址。

【讨论】:

    猜你喜欢
    • 2014-06-11
    • 1970-01-01
    • 2017-11-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    相关资源
    最近更新 更多