Turn服務器的配置流程
Webrtc是基於P2P的,在兩個客戶端建立連接之前需要服務器建立連接,這時兩台設備一般都處於一個或者多個NAT中,那么兩台設備建立連接就需要穿牆技術。
這時就用到了turn服務器,他包括stun服務器,stun服務器主要用來獲得外網的地址,而turn服務器則負責在P2P連接失敗時進行轉發
推薦一個部署turn服務器的方式,下載地址https://github.com/coturn/coturn
下載完成以后進行安裝,cd到下載coturn的目錄下
執行./configure
make
make install
執行時會報錯Libevent2 development is not installed properly
ERROR: Libevent2 development libraries are not installed properly in required location.
ERROR: may be you have just too old libevent tool - then you have to upgrade it.
See the INSTALL file.
說明你需要安裝libevent,以ubuntu為例執行命令進行安裝sudo apt-get install libevent-dev
如果執行成功會在conturn的bin目錄下生成一些文件
配置iceServer
turnserver -o -a -f -v --mobility -m 10 --max-bps=100000 --min-port=32355 --max-port=65535 --user=username1:password1 --user=username2:password2 -r demo –m 10
其中username1和username2分配了兩個不同的賬號和密碼
在服務器內的配置
webrtc的服務器一般使用SkyRTC,下載地址https://github.com/LingyuCoder/SkyRTC-demo
下載后按照文檔進行安裝和配置
配置stun需要在SkyRTC-client.js
內配置iceServers,配置的端口默認是3478,格式如下
“url“: 'stun:ip:3478'
“username”: 'username1’
“password”:’password1’