Dvl*_*lpr 9 video-streaming html5-video webrtc rfc5766turnserver coturn
如何在我的ubuntu 12.04上安装TURN服务器?你能分享教程吗?我读了这篇教程:为WebRTC应用程序实现我们自己的STUN/TURN服务器.但我不明白的是如何在我的ubuntu 12.04上安装自己的TURN服务器?
我正在使用类似以下代码的东西来创建 RTCPeerConnection
const pc_config = {"iceServers": [{"url": "stun:stun.l.google.com:19302"},
{"url":"turn:my_username@<turn_server_ip_address>", "credential":"my_password"}]};
const pc_new = new webkitRTCPeerConnection(pc_config);
Run Code Online (Sandbox Code Playgroud)
我想填写上面代码的参数来使用不同的网络.
当我想安装转服务器然后我得到
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package resiprocate-turn-server
Run Code Online (Sandbox Code Playgroud)
我用过apt-get install resiprocate-turn-server.我还使用了这个https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html教程.
mid*_*ido 22
它很容易在linux机器上安装,而不是在其他操作系统中尝试过.
简单方法:
sudo apt-get install coturn
Run Code Online (Sandbox Code Playgroud)
如果您拒绝,我想要最新的前沿,您可以从他们的下载页面下载源代码,自行安装,例如:
sudo -i # ignore if you already in admin mode
apt-get update && apt-get install libssl-dev libevent-dev libhiredis-dev make -y # install the dependencies
wget -O turn.tar.gz http://turnserver.open-sys.org/downloads/v4.5.0.3/turnserver-4.5.0.3.tar.gz # Download the source tar
tar -zxvf turn.tar.gz # unzip
cd turnserver-*
./configure
make && make install
Run Code Online (Sandbox Code Playgroud)
用于运行TURN服务器的示例命令:
sudo turnserver -a -o -v -n --no-dtls --no-tls -u test:test -r "someRealm"
Run Code Online (Sandbox Code Playgroud)
命令说明:
查看此Wiki以获取更多详细信息和配置.
现在您可以在WebRTC应用程序中使用TURN服务器:
var peerConnectionConfig = {
iceServers: [{
urls: YOUR_IP:3478,
username: 'test',
password: 'test'
}]
}
Run Code Online (Sandbox Code Playgroud)
在您的 ubuntu 服务器机器上,设置、配置和运行coturn的打包版本 。对于基本设置,请执行
# set up
sudo apt-get install --assume-yes coturn
# configure & run
USERNAME="some-username"
PASSWORD="some-password"
PORT=3478
# -n: use only commandline parameters, no config file
sudo turnserver \
-n \
--verbose \
--lt-cred-mech \
--user $USERNAME:$PASSWORD \
--realm "someRealm" \
--no-dtls \
--no-tls \
--listening-port $PORT
Run Code Online (Sandbox Code Playgroud)
添加--daemon以使其在后台运行。有关选项列表,请参阅https://github.com/coturn/coturn/wiki/turnserverturnserver并查看他们的示例配置文件,如果您想使用一个 with-c CONFIGFILE而不是-n像我一样在命令行上使用和传递所有选项上面做了。
要检查它是否有效,请在 Google Chrome 中,同时在安全来源(例如 stackoverflow.com)的任何页面上,在开发人员控制台中运行以下命令:
function checkTURNServer(turnConfig, timeout){
return new Promise(function(resolve, reject){
setTimeout(function(){
if(promiseResolved) return;
resolve(false);
promiseResolved = true;
}, timeout || 5000);
var promiseResolved = false
, myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection //compatibility for firefox and chrome
, pc = new myPeerConnection({iceServers:[turnConfig]})
, noop = function(){};
pc.createDataChannel(""); //create a bogus data channel
pc.createOffer(function(sdp){
if(sdp.sdp.indexOf('typ relay') > -1){ // sometimes sdp contains the ice candidates...
promiseResolved = true;
resolve(true);
}
pc.setLocalDescription(sdp, noop, noop);
}, noop); // create offer and set local description
pc.onicecandidate = function(ice){ //listen for candidate events
if(promiseResolved || !ice || !ice.candidate || !ice.candidate.candidate || !(ice.candidate.candidate.indexOf('typ relay')>-1)) return;
promiseResolved = true;
resolve(true);
};
});
}
const USERNAME="some-username"
const PASSWORD="some-password"
const PORT=3478
const IP="10.11.0.115" // you will have to change this
console.log('TURN server reachable on TCP?', await checkTURNServer( {
url: `turn:${IP}:${PORT}?transport=tcp`,
username: USERNAME,
credential: PASSWORD,
}))
console.log('TURN server reachable on UDP?', await checkTURNServer( {
url: `turn:${IP}:${PORT}?transport=udp`,
username: USERNAME,
credential: PASSWORD,
}))
Run Code Online (Sandbox Code Playgroud)
你应该得到
TURN server reachable on TCP? true
TURN server reachable on UDP? true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23394 次 |
| 最近记录: |