Port allocation behavior
By default, when SFU_SERVER is set to false, the application uses a range of 100 ports.
when SFU_SERVER=true it allocate ports starting from 40000 default + CPU core eg if your server has 4CPU so become 40000 - 40003 (only 3 ports needed)
More about: https://mediasoup.discourse.group/t/mediasoups-webrtcserver-concerning-firewall-settings-and-port-binding/5965/5
Cloudron integration
To support this behavior on Cloudron, SFU_SERVER should be exposed as a toggle (switch button) in the MiroTalk SFU app settings (Location).
When the switch is enabled, the port allocation logic in start.sh can be updated something as follows:
# Enable / disable SFU server (default: false)
readonly SFU_SERVER="${SFU_SERVER:-false}"
# Number of CPU cores (used only when SFU is enabled)
readonly CPU_CORES="$(nproc)"
# Base TCP port (default: 25000)
readonly SFU_TCP_BASE="${SFU_TCP:-25000}"
if [[ "$SFU_SERVER" == "true" ]]; then
# SFU enabled:
# allocate one port per CPU core
readonly SFU_MAX_PORT=$(( SFU_TCP_BASE + CPU_CORES - 1 ))
else
# Default behavior:
# allocate 100 ports starting from the base port
readonly SFU_MAX_PORT=$(( SFU_TCP_BASE + 100 ))
fi
Benefits of this approach
Fewer ports allocated
Only the ports that are actually needed are opened, especially in SFU mode.
Reduced port conflicts
Smaller port ranges significantly lower the chance of clashes with other services on the same host.
Better Cloudron compatibility
Minimal port exposure aligns well with Cloudron’s strict networking and security model.
Scales with hardware
Port allocation automatically adapts to the number of CPU cores available.
User control
Exposing SFU_SERVER as a switch allows users to explicitly choose whether to run in SFU mode or keep the default behavior.