mediasop 3.14.0 has been released with portRange in TransportListenInfo

Hi, mediasop 3.14.0 has been released with portRange in TransportListenInfo.

Details

  • New optional portRange field of type TransportPortRange has been added in TransportListenInfo, so it’s available in router.createWebRtcTransport(), router.createPlainTransport(), router.createPipeTransport() and worker.createWebRtcServer() methods.

  • If portRange is given, then a free random port in that range (and given ip and protocol) will be chosen.

  • This feature deprecates worker ports range (rtcMinPort and rtcMaxPort in WorkerSettings given to createWorker() method). Rationale is that it doesn’t make any sense to have a unique port range for different listening IPs (for example: an app may want to use different port ranges for public connections (public internet) and private connections (private network).

  • Here the corresponding PR: TransportListenInfo: Add portRange (deprecate worker port range) by ibc · Pull Request #1365 · versatica/mediasoup · GitHub

  • Bonus track: Node >= 18 is required (so mediasoup no longer runs in Node 16).

4 Likes

Nice, make sense, thank you!

Just a few questions:

  1. Regarding webRtcTransportOptions, can the same portRange be used for both UDP and TCP listenInfos, or must they be different ranges?
    webRtcTransportOptions {
       listenInfos: [
           { protocol: 'udp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 40000, max: 40100 }},
           { protocol: 'tcp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 40000, max: 40100 }},
       ],
   }
  1. For configuring the webRtcServer, are both of these configurations valid?

    a. Using a single port:

    webRtcServerOptions: {
        listenInfos: [
            { protocol: 'udp', ip: '0.0.0.0', announcedAddress: IPv4, port: 44444 },
            { protocol: 'tcp', ip: '0.0.0.0', announcedAddress: IPv4, port: 44444 },
        ],
    },
    

    b. Using a portRange:

    webRtcServerOptions: {
        listenInfos: [
            { protocol: 'udp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 44444, max: 44444 } },
            { protocol: 'tcp', ip: '0.0.0.0', announcedAddress: IPv4, portRange: { min: 44444, max: 44444 } },
        ],
    },
    
  2. If the WebRtcServer is designed to work with a single port per worker (without need to open large ports range in the firewall), why would someone need to use a portRange in this case?

Why should they be different? :grinning:

As per the documentation both approaches do the same.

When creating many workers, each one with its own WebRtcServer.

Yeah, got it, but why would one choose to specify a portRange in the ListenInfos of a WebRtcServer when typically a single port should be sufficient, especially in scenarios involving multiple workers each with its own WebRtcServer?

Edit: Maybe for Load Distribution: By defining a range of ports rather than just one, the WebRtcServer gains the ability to distribute incoming connections across multiple ports. This can help in balancing the load more efficiently, especially in high-traffic environments.

  • You have ports 20001-20008 open in your host.
  • You create 8 workers and in each worker you create a WebRtcServer with portRange: { min: 20001, max: 20008 }.
  • All ports will be used and you don’t need to care about assigning fixed ports.

Not sure what you mean. portRange is not about opening many ports. It’s about opening a single port in the given port range. Which one? Any available random port.

hi, If one port is given instead of port range then only that port will be used by all workers, and mediasoup will not have any issues dealing the packet with that single port?

As the documentation says two workers cannot listen in same port.

Thank you for the explanation :wink:

Perhaps it’s necessary to also revisit this section in the mediasoup demo. Here, it appears that ports are being allocated dynamically without consideration for whether the portRange is set in the WebRtcServerOption listenInfos.

Below is a suggested improvement:

if (!listenInfo.portRange) 
{ 
   listenInfo.port += portIncrement;
}

Thanks, everything is clearer to me now.

In config.js we don’t pass any portRange to WebRtcServer but a single port. I understand your point but honestly nobody should take mediasoup-demo as a reference app.

This topic was automatically closed after 2 days. New replies are no longer allowed.