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

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.

Related

STUN and TURN Server

I have developed a webrtc based video chat using peerjs. The solution is working fine but some users are facing problem to establish the call. I guess it is due to NAT and firewall issues.
I have user peerjs as :
var peer = new Peer({host: myserver.com], port: 9000, debug: true});
I have changed the code to [passed google stun] as seen here : =
Still the same issue. Some user can not connect to peer id. Am I doing something wrong?

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

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.

Is ICE Necessary for Client-Server WebRTC Applications?

I have a WebRTC MCU (kurento) running on a public IP address
serving some clients that only send or only receive audio
So every clients is directly connected with MCU (not with each other ) that has a public IP address .
Q1: Is there still a necessity to use STUN and TURN for NAT traversal ?? if so Why ??
Q2: Is there any hack in WebRTC in browser that would remove the need for STUN and TURN ?
In my opinion : most of client-server architectures do not have any difficulty with clients behind NAT .What's the difference here with webrtc?
Yes ICE is absolutely must for WebRTC.
Q1: Is there still a necessity to use STUN and TURN for NAT traversal
?? if so Why ??
For your scenario you don't need to use STUN or TURN. Let me explain why.
Every client that are in private network is under some kind of NAT which has a public IP address. Outside world doesn't know this client's private IP address and even if they knew they can't connect with the client without knowing that public IP address. STUN server is used to gather this public IP address.
So if your server wants to initiates the connection then it needs the client to send its NAT's public IP. Client will use STUN server to know its public IP and send it to the server. But if client initiates the connection then there is no need to know the NAT's public IP. Client can send packets to the public server to initiate the connection. Server can know the cilents public IP from the clients packet and then they can connect. So no need for STUN.
Your server is doing TURN's role in this scenario. So you don't need TURN server.
Q2: Is there any hack in WebRTC in browser that would remove the need for STUN and TURN ?
There is no hack. Depending on scenarios TURN/STUN is used. For your scenario you don't need. If you wanted to make client-client connection then you would have needed STUN server.
ICE is mandatory
but using any stun and turn server is not.
since you are connecting to a server on a public port, you NEVER need to use a TURN server, but depending the kind of NAT/Firewall your clients are behind, you might need a STUN server
you do not need to modify the browsers at all. The application decides wether to use a stun server or not. if you pass an empty "iceservers" parameter to your peerconnection object at creation, the ICE UA in your browser will only generate host (local) candidates.

How to replace Ip Address for peer-to-peer connection for media in WebRTC app?

I am writing WebRTC application for windows. My scenario is like:
LAN is default network interface for all applications.
System has more than one network interfaces like LAN and Wifi or usb modem.
WebRTC Signaling should use LAN & media (peer-to-peer connection) should use Wifi network. So that application can get fast network access for media communication.
Question- How to replace the Wifi Ip Address from LAN IP Address for media
communication (peer-to-peer connection)?
My observation is:
It is possible to print Private and Public ICE candidates as per blow code.
pc.onicecandidate = function(evt) {
if (evt.target.iceGatheringState == "complete") {
local.createOffer(function(offer) {
console.log("Offer with ICE candidates: " + offer.sdp);
signalingChannel.send(offer.sdp);
});
This code prints below info in my case.
Private ICE candidate (192.168.1.73:60834) for the peer
Public ICE candidate (50.76.44.100:69834) returned by the STUN server.
Now how to replace the Private ICE conditate (IP Address) to Wifi (IP Address)?
Could you please suggest any solution?