简体   繁体   English

如何通过NAT流式传输WebRTC音频?

[英]How to stream WebRTC audio through a NAT?

I have a WebRTC multi-party app that works on both localhost and on an ngrok.io localhost tunnel. 我有一个可同时在localhost和ngrok.io localhost隧道上使用的WebRTC多方应用程序。 However, when I try and test it with my friend, who is connected through a router on their end, I am able to see an offer/answer exchange as well as an ICE candidate exchange, but no sound gets streamed through. 但是,当我尝试与通过路由器连接的我的朋友进行测试时,我可以看到要约/答案交换以及ICE候选交换,但是没有声音通过。

After first having this problem, I did some research and learned that you need a TURN server to get through a router's NAT. 第一次遇到此问题后,我进行了一些研究,了解到您需要TURN服务器才能通过路由器的NAT。 I'm using a public TURN server that I've confirmed works in https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ 我正在使用已确认在https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/中起作用的公共TURN服务器

var configuration = { 
    "iceServers": [{ "url": "stun:stun2.1.google.com:19302" }], 
     url: 'turn:192.158.29.39:3478?transport=udp', 
     credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', 
     username: '28224511:1379330808' 
}; 

yourConn = new webkitRTCPeerConnection(configuration); 

yourConn2 = new webkitRTCPeerConnection(configuration); 

yourConn3 = new webkitRTCPeerConnection(configuration);

The sound packets should be routed through this TURN server and through my friend's NAT, but we still can't stream to each other. 声音数据包应通过此TURN服务器和我朋友的NAT进行路由,但我们仍然无法彼此流式传输。

Your turn server credentials are taken from https://www.html5rocks.com/en/tutorials/webrtc/infrastructure/ and have expired in 2013. If you used https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ it should have told you this doesn't work -- i'd be rather surprised if it gave you relay candidates. 您的转弯服务器凭证来自https://www.html5rocks.com/cn/tutorials/webrtc/infrastructure/ ,并且已于2013年过期。如果您使用https://webrtc.github.io/samples/src/content/ peerconnection / trickle-ice /它应该告诉您这不起作用-如果它给您中继候选人,我会感到很惊讶。

Run your own server. 运行您自己的服务器。

You should change configuration: 您应该更改配置:

var configuration = { 
  "iceServers": [
    { "url": "stun:stun2.1.google.com:19302" },
    {
      "url": "turn:192.158.29.39:3478?transport=udp", 
      "credential": "yourpassword", 
      "username": "yourusename" 
    }
  ], 

}; };

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

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