How can I install a TURN server on my ubuntu 12.04? Can you share tutorial? I read this tutorial: Implementing our own STUN/TURN server for WebRTC Application. But what I don't understand is how I can I install my own TURN server on my ubuntu 12.04?
I am using currently using something like the following code to create the 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);
And I want to fill the above code's arguments to work with a different network.
When i want to install turn server then I get
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package resiprocate-turn-server
I used apt-get install resiprocate-turn-server
. I also used this https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html tutorial.
it is easy to install in linux machines, not tried in other OSes.
simple way:
sudo apt-get install coturn
If you say no, I want the latest cutting edge, you can download source code from their downloads page in install it yourself, example:
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
sample command for running TURN server:
sudo turnserver -a -o -v -n --no-dtls --no-tls -u test:test -r "someRealm"
command description:
- -a - Use long-term credentials mechanism
- -o - Run server process as daemon
- -v - 'Moderate' verbose mode.
- -n - no configuration file
- --no-dtls - Do not start DTLS listeners
- --no-tls - Do not start TLS listeners
- -u - user credentials to be used
- -r - default realm to be used, need for TURN REST API
check this wiki for more details and configurations.
now you can use the TURN server in your WebRTC application as:
var peerConnectionConfig = {
iceServers: [{
urls: YOUR_IP:3478,
username: 'test',
password: 'test'
}]
}
I think the guide is somewhat outdated.
Look at this Google open source TURN server.
Really easy to install and works very well.
https://code.google.com/p/rfc5766-turn-server/
On your ubuntu server machine, set up, configure & run a packaged version of coturn. For a basic setup, do
# 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
Add --daemon
to keep it running in the background.
See https://github.com/coturn/coturn/wiki/turnserver for the list of options of turnserver
and have a look at their example config file if you want to use one with -c CONFIGFILE
instead of using -n
and passing all options on the commandline like I did above.
To check that it worked, in Google Chrome, while on any page of a secure origin (for example stackoverflow.com), run this in the developer console:
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,
}))
You should get
TURN server reachable on TCP? true
TURN server reachable on UDP? true
This link will provide all details regarding installation and configuration of TURN server.
https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html
The guy has very good repository for WebRtc demos.
Turn Server Installation
change the package according to your server
wget http://turnserver.open-sys.org/downloads/v3.2.4.4/turnserver-3.2.4.4-debian-wheezy-ubuntu-mint-x86-64bits.tar.gz
tar -zxvf turnserver-3.2.4.4-debian-wheezy-ubuntu-mint-x86-64bits.tar.gz
wget http://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar -zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable/
./configure
make && make install
dpkg -i rfc5766-turn-server_3.2.4.4-1_amd64.deb
cd /etc/
vi turnserver.conf
Add following to turn server.conf
listening-device=eth0
listening-ip=YOUR_IP_HERE
listening-port=3478
userdb=turnuserdb.conf
relay-device=eth0
realm=YOUR_REALM_IP_HERE
lt-cred-mech
log-file=/var/log/turnserver.log
Add the username and password on turnuserdb.conf
vi turnuserdb.conf
in the following format
testuser:pass0wrd
To Start the Turn Server:
sh /data/start_turn_server.sh
To add new Turn User:
sh /data/ addTurnUser.sh
To See if the Turn Server is running :
ps aux | grep –I turn
The above command should list some processes as turnserver , if the TURN server is running properly.
来源:https://stackoverflow.com/questions/25546098/installing-a-turn-server-on-ubuntu-for-webrtc