How could webRTC works without peerConstraints?

Hi Folks,
I’m new to webRTC and React-Native.
Although, from the code of Geoff Chen GitHub - geoffcfchen/webRTC-react-native-firebase-expo, I succeeded to create an app which works in my local network.

Of couse, if i keep one device on the local network, and set the other device on 4G network, it stops to work… …so I’m planning to deploy a coturn docker container soon.

Nevertheless, there is something I dont understand…

In the code, we are setting peerConstrainf to :

export const peerConstraints = {
  iceServers: [
    {
      urls: [
        "stun:stun.l.google.com:19302",
        "stun:stun1.l.google.com:19302",
        "stun:stun2.l.google.com:19302",
      ],
    },
  ],
  iceCandidatePoolSize: 10,
};

and call it while setting up the webRTC layer by :

pc.current = new RTCPeerConnection(peerConstraints);

Everything is fine…
Although, if I do :

pc.current = new RTCPeerConnection();

Everything still works (while on local network)

I dont understand why ?

Can someone explain it to me ?

Best Regards,
Edouard

By default WebRTC will connect to any internal/external addresses as long as they are accessible.
When using STUN/TURN servers you are usually targeting external networking.
But as things go, a lot of networks tend to implement the use of a NAT.
Which then means you’d need a STUN/TURN server to accomplish a stable connection.

1 Like

Thank you so much for your answer ! So actually, if both are on my local network, you mean that not even the STUN server is reached ? …sorry to confirm, just, i’m really new to this… :wink:

If both devices are on your local network and you don’t have any weird network setup/conditions then you can use WebRTC internally without the requirement of a STUN/TURN server.
It only becomes complex and unstable when trying to connect externally or if you have a bit of a restrictive network. For example, some wireless networks have client isolation enabled which means devices will only get internet access but can’t connect to each other.

Thanks for your answer… …in fact you help me both on the discourse and the github… Cool Buddy !! :wink:

1 Like

No worries, you’re welcome :slight_smile: