为什么我的 WebRTC 代码在没有指定 STUN/TURN 服务器 url 的情况下工作?

Why my WebRTC code is working without specifying STUN/TURN server url?

我已经能够使用 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);
        }

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

2) 设备使用 STUN 服务器访问自己的 public 地址。 (由于两个设备都在不同的网络上,它们无法相互连接,因为它们彼此不知道 public IP 地址。如果它们彼此知道 public IP 地址,则可以建立 P2P 连接)

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

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

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