If the client is situated behind a NAT, two ports for the audio stream must be opened on the NAT to allow the media to be forwarded to that client machine. In addition, the client IP address must be mapped to an IP address on the NAT so that the NAT can forward the media stream to the correct device. If the NAT supports UPnP functionality, the RTC Client API will automatically provide the NAT mappings. This is the default behavior of the API (see the Firewalls and NATs topic). When the client is situated behind a NAT that does not support UPnP functionality, the client application should provide a means to map the IP addresses and ports on the NAT to those on the client machine. The RTC Client API will support non-UPnP mappings only if the client application specifically calls these methods.
The port manager is a component of the application that provides the functionality of port mapping for the RTC Client API. To set up the mappings, the application can perform a QueryInterface on any session object to obtain the IRTCSessionPortManagement interface. The IRTCSessionPortManagement interface is available only on PC-phone sessions for the RTC Client API Version 1.01 and on PC-PC sessions starting with the RTC Client API Version 1.2. The only method on the IRTCSessionPortManagement interface is SetPortManager. This method allows the client application to specify a callback interface (IRTCPortManager) used by the RTC Client API to obtain port mappings from the application.
The client application must specify the interface that enables the RTC Client API to query for the port and address mappings before the session is initiated with the IRTCSession::AddParticipant method. Adding a participant to an idle session will initiate the session; if the NAT mappings are not in place, the desired media streams will not be transmitted. (A session is initially created as idle and remains idle until a participant is added.)
The RTC Client API will automatically call the methods on this interface for PC-phone sessions (for version 1.01 applications) and PC-PC sessions (for version 1.2 applications) only when this interface has been supplied by the client application. Given the address of the remote endpoint and the media type, the client application's implementation of the IRTCPortManager::GetMapping method must return the IP address and port on the client as well as the external IP address and port on the NAT.
Note The application should be prepared to return the port mappings immediately after the application calls IRTCSessionPortManagement::SetPortManager.
The external address and port on the NAT are used in the Session Description Protocol of the SIP INVITE message when a participant is added to the session.
For more detailed information on how to initiate a session using the port manager interfaces, see The Client Application is behind a NAT. For more information on how to set the port mapping interface, see Port Manager Code Example.