Server behind NAT and the announcedIp

Consider a mediasoup server inside a LAN and behind NAT, when listenIps.announcedIp is set then all clients connects through the public IP. However in some strict network configurations users are denied to access the outside of the network. I’m just wondering is there a way for clients inside the network to connect through the local IP of the server (i.e. listenIps.ip)?

Please check the WebRTC transport options. You can set per transport listen IPs. It’s not something global for all.

Ah you are right! So I just need to detect local clients. Any tips for that?

Checking the client IP against the standard private IP range should work.

Private IP Address Reservation:

10.0.0.0 to 10.255.255.255 - Class A
172.16.0.0 to 172.31.255.255 - Class B
192.168.0.0 to 192.168.255.255 - Class C

Sometimes, even when I set the listenIps.announcedIp, mediasoup picks the listenIps.ip and not the announcedIp (inspected using Chrome webrtc-internals). How is that possible?!

Not sure what “inspected using Chrome webrtc-internals” means here. It’s completely unrelated. You may want to read how ICE works, specifically what “ICE reflexive candidates are” but that’s out of the scope of mediasoup.

mediasoup binds on the given listenIp.ip. It just uses the given listenIp.announcedIp in the generated transport.iceCandidates array, nothing else.

1 Like

Some times (completely random) the private IP is taken while I’ve set the announcedIp with a public IP when creating the transport:

I’m afraid you just ignored everything I said in my response.

In summary: there is no issue even if you see that in chrome internals.

Print transport.iceCandidates (those you provide your client side with) and check whether they look fine. That’s the only thing that matters here.

Sorry it was my fault:

const config = {
  webrtc : {
    listenIps: { ip: '192.168.1.100', announcedIp: '10.20.30.40' },
  }
};
const { listenIps } = config.webrtc;
if (clientIsLocal()) {
  listenIps.announcedIp = null;
}

The code will change the config for ever :grimacing:

And here’s the fix:

const listenIps = Object.assign({}, config.webrtc.listenIps);

Thanks for your help :pray: