如何通過 NAT 流式傳輸 WebRTC 音頻? (How to stream WebRTC audio through a NAT?)


問題描述

如何通過 NAT 流式傳輸 WebRTC 音頻? (How to stream WebRTC audio through a NAT?)

我有一個 WebRTC 多方應用程序,可在 localhost 和 ngrok.io localhost 隧道上運行。但是,當我嘗試與通過路由器連接的朋友進行測試時,我能夠看到提議/答案交換以及 ICE 候選交換,但沒有聲音通過流式傳輸。

在第一次遇到這個問題後,我做了一些研究,了解到你需要一個 TURN 服務器才能通過路由器的 NAT。我正在使用我已確認在 中工作的公共 TURN 服務器https://webrtc.github.io/samples/src/content/peerconnection/trickle‑ice/

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);

聲音數據包應該通過這個 TURN 服務器和我朋友的 NAT 路由,但我們仍然無法相互傳輸。


參考解法

方法 1:

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.

Run your own server.

方法 2:

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" 
    }
  ], 

};

(by John SmithPhilipp HanckeUyen Do)

參考文件

  1. How to stream WebRTC audio through a NAT? (CC BY‑SA 2.5/3.0/4.0)

#javascript #audio-streaming #webrtc #nat #turn






相關問題

為什麼我不能在 IE8 (javascript) 上擴展 localStorage? (Why can't I extend localStorage on IE8 (javascript)?)

在 Javascript 中打開外部 sqlite3 數據庫 (Open external sqlite3 database in Javascript)

Javascript:數組中的所有對像都具有相同的屬性 (Javascript: All Objects in Array Have Same Properties)

為什麼我們要在 javascripts 原型中添加函數? (Why do we add functions to javascripts prototype?)

顯示 URL javascript 的最後一部分? (Display the last part of URL javascript?)

Javascript XMLHttpRequest:忽略無效的 SSL 證書 (Javascript XMLHttpRequest: Ignore invalid SSL Certificate)

有沒有辦法測試 console.log 整體 (Is there a way to test for console.log entires)

如何從 javascript 對像中獲取名稱和值到新列表中? (How to get name and values from a javascript object into a new list?)

數據未發布..幫助!html,js,firebase (Data not posting.. Help! html,js,firebase)

使用 Node.js 腳本查看表單數據 (Seeing form data with Node.js script)

使用百分比查找範圍內的值 (find the value within a range using percent)

如何通過 react.js 中的組件傳遞變量或數據? (How to pass varible or data through components in react.js?)







留言討論