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: to - Class A to - Class B to - 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: '', announcedIp: '' },
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: