Can WebRtcServer determine the port automatically?

In WebRtcServer, Is there any technical reason why this cannot be determined automatically from the worker’s port range like other Transports?

If there is none, I will create a PR.

I would love for a port-range to be available with this feature, as we many summon more workers and it could conflict and we may need more fixed ports in a range like setting.

Quoting from the API documentation

A WebRTC server brings the ability to listen on a single UDP/TCP port to WebRtcTransports

See it as “WebRtcServer makes it possible for a WebRtcTransports to listen on a single specified UDT/TCP port instead of automatically choosing from a port range

Hoping my understanding of your post is correct, I believe what you are asking after is already the default mechanism when using only WebRtcTransport

It’s not. We supply the port and if it doesn’t work there’s no later option as in a further port in this case. If one ran several workers per core, they’d need ports say 443->447 but when summon the workers it’s unknown which port is available for fixed use.

The app can manage ports by keeping a list of available and used ports and assigning an available one to every WebRtcServer being created. We have done it at Node.js level in our company, it’s perfectly feasible and we want to avoid as much sugar API in mediasoup as possible.

3 Likes

I understand that this can be accomplished at the application level and that you don’t want to include an much sugar API.
But webrtc is not the only one that uses port (Pipe and PlainTransport), so we are faced with two choices when using a WebRTC server and these Transports at the same time.

  • Complete management of all ports, including Transport, in the application. (rtcMinPort and rtcMaxPort of WorkerSettings would be useless options.)
  • Separate the port range used between those Transports and the WebRtcServer. (The wide rtcMinPort and rtcMaxPort ranges of default values are probably superfluous. It is also a bit annoying to think about how much should be allocated to which side.)

So, users who used rtcMinPort and rtcMaxPort have a hurdle in using WebRtcServer.

Port management will be totally refactored in v4. In the meantime I would accept a PR that makes port optional in WebRtcServer and selects a random port in the range of ports given to the worker, as far as:

  • It is done in Node and Rust.
  • It includes tests in Node and Rust.