-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Feature Request: Support for Port Mapping in Docker Deployments
Description:
When deploying Pion-based WebRTC applications in Docker containers, there's often a mismatch between the port that the application listens on internally and the port that's exposed/forwarded to the outside world through Docker's port mapping. This creates issues during SDP negotiation, where the peer expects to connect to the mapped port (e.g., 3478 on the host) but the SDP offers/answers contain the internal container port (e.g., 3478 inside the container).
Current Behavior:
Pion currently binds to and advertises the port it listens on internally within the container. When Docker maps this internal port to a different host port (e.g., -p 3478:3478), the SDP still contains the internal port, causing connection failures since peers attempt to connect to the wrong port.
Requested Feature:
Add support for port mapping awareness in Pion, where:
1.The library can be configured with a port mapping (internal vs. external ports) during initialization or when creating transports.
2.The SDP offers/answers are automatically adjusted to advertise the externally mapped port instead of the internal port.
3.This should work seamlessly for both UDP and TCP-based transports (ICE candidates).
Use Case Example:
A Docker container running a Pion-based SFU (Selective Forwarding Unit) listens on port 3478 internally. Docker maps this to host port 5000 (-p 5000:3478). When generating SDP, Pion should advertise port 5000 instead of 3478 so that peers connect to the correct host port.
Implementation Suggestions:
Add a SetPortMapping(internalPort, externalPort) method to the API or transport interfaces.
Modify ICE candidate generation to use the mapped port when appropriate.
Ensure backward compatibility (default to internal port if no mapping is configured).
Impact:
This feature would greatly simplify WebRTC deployments in containerized environments, making Pion more production-friendly for cloud-native setups.