0

I'm trying to understand a bit more about webRTC so:

  1. My guess is that when running an app from localhost and establishing a peerConnection with myself ( no firewalls, vpns or symmetric nats involved ), WebRTC will connect locally using 127.0.0.1 adress.
  2. Now if I run my app from the web my other guess would be that webRTC will be using my public ip adress to finally try to connect to my same public ip adress.

So my question is, when connecting from localhost I'm pretty sure WebRTC peerConnection doesn't go through internet to connect to myself, will this be the same with the second scenario?

JSmith
  • 4,519
  • 4
  • 29
  • 45
  • localhost itself is not on the list of locally gathered candidates (from your enumerated network devices) since every other peer would try (and fail) to connect to itself which is undesirable – Philipp Hancke Aug 12 '22 at 05:27
  • @PhilippHancke Thank you for your answer but I'm not sure to understand what you are telling me. Could you try explaining in a differrent manner? – JSmith Aug 12 '22 at 05:58
  • 1
    this was merely a comment on your mention of "localhost" aka 127.0.0.1. The answer below is a great one – Philipp Hancke Aug 14 '22 at 11:55

1 Answers1

2

Whether WebRTC goes through internet or not depends on what you pass in ICE server list when creating a peer. If you don't pass any ICE server (STUN or TURN), then WebRTC just gathers local ICE candidates (i.e. from localhost). If you pass at least one STUN or TURN server url, then WebRTC tries to gather ICE candidates using that servers. But even though you provide non-empty ICE server list, if both peers can reach each other using local candidates (of course, if you haven't disabled gathering local ICE candidates), then its likely that WebRTC would select them as the best candidates pair, because they have lower "network cost" for sending media than the candidates gathered from outside of localhost.

Artem Suprunov
  • 323
  • 1
  • 7