Implementing our own STUN/TURN server for WebRTC Application [duplicate] - webrtc

This question already has answers here:
Installing a TURN Server on Ubuntu for WebRTC
(5 answers)
Closed 2 years ago.
I am working on a webrtc application and have to implement following TURN server.
https://code.google.com/p/rfc5766-turn-server/
I am following this tutorial.
http://www.dialogic.com/den/developer_forums/f/71/t/10238.aspx
and it says to reference the TURN server as follows, in javascript code where RTCPeerConnection is created.
var pc_config = {"iceServers": [{"url": "stun:stun.l.google.com:19302"},
{"url":"turn:<turn_server_ip_address>", "username":"my_username", "credential":"my_password"}]};
pc_new = new webkitRTCPeerConnection(pc_config);
I am little confused, why are we referencing to Google's public STUN server. I thought RFC5766 TURN server has STUN inside it.
Is RFC5766 only TURN server? and not STUN server? Can't we implement our own STUN server rather using one provided by Google?
Sorry for such naive question. I am new to WebRTC.
Thanks.

TURN it's an extension of STUN, so TURN server has also STUN features.
https://code.google.com/p/rfc5766-turn-server/ works also as a STUN, so you can try to write something like this:
var pc_config = {
"iceServers": [{
"url":"turn:my_username#<turn_server_ip_address>",
"credential":"my_password"
}]
};
pc_new = new webkitRTCPeerConnection(pc_config);

Recently I was capturing my Kurento WebRTC server packets and realized that it has been using this www.stunprotocol.org domain for STUN requests. A tool named stuntman can create a simple STUN server for you.
Just follow these on a Linux host:
sudo apt-get update
sudo apt-get install stuntman-server
stunserver --mode full --primaryinterface 100.101.102.103
(which the 100.101.102.103 should be replaced by your IP address)
Open This Link to test your STUN server.
e.g. STUN or TURN URI:
stun:100.101.102.103:3478
By this procedure I've mentioned, everything goes well on my machine.

Related

How to setup STUN server in a video chat app built using simple peer?

I was recently working on a project which requires video chatting. I used simple peer to setup a video call and use socket.io for signalling purposes. I then deployed my application. I realised when two peers on the same network join the call, the app works fine. But if two peers on different networks join the call, then I got an error stating process not defined and the call does not connects.
I read about this online and then figured out that I also have two configure a STUN and/or TURN server to extract ICE candidates and their public IP.
Can anyone please tell me how to setup a STUN server in my simple peer application? I have also read somewhere that google provides some free STUN servers to use but I dont know how to actually integrate them in my simple peer application.
When you create the RTCPeerConnection in your application, provide a configuration that includes iceServers.
This is the reference.
Example:
myPeerConnection = new RTCPeerConnection({
iceServers: [
{
urls: "stun:stunserver.example.org"
}
]
});
You can find a list of free STUN servers here.
You may also want to configure TURN servers to cover more complex NAT scenarios.

WebRTC call between two networks connected to the same server

I currently have the following network setup and would like to be able to make WebRTC calls between the two clients in different networks.
I enabled IPv4 forwarding on the openSuse Leap 15.2 server and both devices have either 192.168.2.1 or 192.168.4.1 as their default gateway. The web application as well as the signaling service are both hosted on this server as well.
With the Firewall disabled the call works as suspected, but with the Firewall on the call no longer works. I thought about hosting a Coturn STUN/TURN server on this server, as I've read that you should provision one, if you run into troubles with a firewall.
Is a setup like this doable with lets say Coturn and what would the configuration look like for a scenario like this?
I ended up solving it as I describe in my GitHub issue for this matter.

local stun server inside a closed LTE network

First of all, apologies if the title doesn't match the description.
We, in our organization are working on peer-peer video communication solution within a closedLTE network. For this purpose, we are using open source webrtc client peerjs along with their local peerjs server. The server by default refers to google stun server.
1. Is stun server required in case of closed LTE network?
2. If yes, can we make use of a open source stun server which could run locally instead of the default one?
3. If no, what are the changes I would need to do?
I have setup one open source stun server [https://github.com/enobufs/stun] but failed to carry out further connections with the clients.
I setup the server as per the instructions provided in the link. Now instead of the default stun server , I put the 'local-ip-address:port' and tried to make a connection between the peers. But it dint work.
var configuration = { "iceServers": [{ "urls": "local-ip-address:port" }] };
pc = new RTCPeerConnection(configuration);
Am i doing it the wrong way?
Please guide me through.
Thanks in advance
Coturn is very popular stun/turn server with active community support.
Pre-built packages available at https://github.com/coturn/coturn/wiki/Downloads
You can test the server with sample demo
If both the parties are in same network, then no need to configure turn stuff like credentials. Read more
Configuring the peerConnection:
STUN server: //server_ip is coturn instance ip should be reachable from clients
var iceServers= [{"url": "stun:server_ip:port"}];
or TURN server:
var iceServers= [{"url":["turn:server_ip:port"],"username":"turn_username","credential":"turn_password"}];
var pc_config = {"iceServers": iceServers};
var pc_constraints = {
"optional": [{"DtlsSrtpKeyAgreement": true}]
};
pc = new RTCPeerConnection(pc_config, pc_constraints);

WebRTC on isolated LAN without ice/stun/turn server

On an isolated LAN, is there any way that a WebRTC connection can be made simply with the IP addresses assigned by the DHCP server?
I understand that I can accomplish this with Node.js and Socket.io - but I was really hoping to avoid setting up that kind of server with my limited skill set. I'm a science teacher who dabbles in programming, so feel free to keep it simple. Thank you!
UPDATE
Alex, you are correct that I can avoid using a STUN server if all of the computers are on the same local network. Although I had to bite the bullet and install Node.js on my laptop, it was really wasn't complicated. I then tried a whole bunch of 'working examples' that didn't work for me, until I found this one and his GitHub files.
After running the server script in Node, I had a DataChannel connection between two browser windows on the same machine, but not between different computers. I edited the .html files to point to my local server IP address instead of localhost and I could then connect with multiple computers. Then came the real test - could I use this without an internet connection? I found the line that specified using Google's STUN servers and changed it from
var config = {"iceServers":[{"url":"stun:stun.l.google.com:19302"}]};
to just
var config = {"iceServers":[]};
It worked. :-)
Omit the iceServers list:
const pc = new RTCPeerConnection();
Either omit the iceServers list from the RTCPeerConnection constructor, or make it the empty list [].
From RTCPeerConnection docs:
iceServers | optional
An array of RTCIceServer objects, each describing one server which may be used by the ICE agent; these are typically STUN and/or TURN servers. If this isn't specified, the connection attempt will be made with no STUN or TURN server available, which limits the connection to local peers.
webrtc/samples demo
The WebRTC project has a Trickle ICE sample that you can use to see how changes in iceServers effect the candidate address that are gathered. The specific sample you want to look at is.
Run it with defaults set by pressing the Gather candidates button at the bottom of the page. This will return a list of addresses which include the address of the public side of your NAT.
Now remove all the ICE servers from the list and press Gather candidates again, this time you should only see local network addresses.
Notice that, on my network, the 2 public IPv4 addresses (beginning with 98.) only appear when I'm using the default ICE servers. When I use an empty ICE server list, my public IPv4 addresses are no longer discovered. My IPv6 addresses, on the other hand, are the same in both tests because they aren't subject to NAT.
Here is a link to the source code that sets up iceServers and PeerConnection.
Alex, you are correct that I can avoid using a STUN server if all of the computers are on the same local network. Although I had to bite the bullet and install Node.js on my laptop, it was really wasn't complicated. I then tried a whole bunch of 'working examples' that didn't work for me, until I found this one and his GitHub files.
After running the server script in Node, I had a DataChannel connection between two browser windows on the same machine, but not between different computers. I edited the .html files to point to my local server IP address instead of localhost and I could then connect with multiple computers. Then came the real test - could I use this without an internet connection? I found the line that specified using Google's STUN servers and changed it from
var config = {"iceServers":[{"url":"stun:stun.l.google.com:19302"}]};
to just
var config = {"iceServers":[]};

rfc5766-turn-server as TURN and STUN for webrtc application

I have implemented rfc5766-turn-server and have it running on my own server.
in the app, I set :
pc_config = {"iceServers": [{"url":"turn:username#<turn_server_address>", "credential":"password"}]};
it seems to be working, but I have couple of questions:
is having the app set this way , with rfc5766-turn-server is enough to act as a TURN and also STUN server
or do I also need to run a stun server.
a turn server is also stun so will the rfc5766-turn-server function as a stun server (on most cases) and a turn server when needed?
for testing purposes it seems to work fine with the username and password given in the app, but eventually when the app is in production and have many users , do all users use the same username/password for the TURN server??
hope my question make sense...
Thanks
Yes, that server will try to act as a stun server first(you can configure it that way) but if that fails it will run work as a turn server.
Which ever way you want. You can have static long-term credentials or configure TURN REST API(which they support).