local stun server inside a closed LTE network - webrtc

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

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.

Why my WebRTC code is working without specifying STUN/TURN server url?

I have been able to connect peer to peer device using webrtc. The question in my mind is that the RTCPeerConnection()- here we pass the stun/turn urls. But it is also working when nothing is passed !
I would like to know is it using google stun server internally and if yes why is it not mentioned in any of their documentations.
peerConnection = new RTCPeerConnection();
peerConnection.setRemoteDescription(description)
.then(() => peerConnection.createAnswer())
.then(sdp => peerConnection.setLocalDescription(sdp))
.then(function () {
socket.emit('answer', id, peerConnection.localDescription);
});
peerConnection.ontrack = function(event) {
video.srcObject = event.streams[0];
};
peerConnection.onicecandidate = function(event) {
if (event.candidate) {
socket.emit('candidate', id, event.candidate);
}
1) You don't need STUN server in local network.
2) STUN server is used by device to access own public address. (As both device are on differnet network they can't connect to each other because they don't know each other public IP address. If they know each other public IP address, they can establish P2P connection)
3) TURN server is used as backup server. (When UDP hole punching dosen't work). TURN server traverse whole data because P2P connection cannot be established.
If your testing on local network then there is no need of STUN server.
To use STUN server you do need to specify IP address.

deepstream is it possible to publish from my server, without opening a client connection in a browser

I am somewhat confused in deepstream, is it possible to communicate to a client from my server? For example, is there any way to do something like this on a server? I am currently opening a client connection in browser that publishes to other clients. I would rather have the code below in my server.
var client = deepstream('localhost:6020').login()
var record = client.record.getRecord('new-record')
#Publish a message to all listeners of 'listen-channel' from my server?
record.set('listen-channel', 'message');
and then have clients listen:
record.subscribe('listen-channel', function(value) {
console.log(value);
Sure, just run it from a node process. Deepstream "clients" can be backend and frontend processes alike, permissioning is used to distuinguish between who can do what.

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":[]};

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

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.