ossrs/srs

How to use TURN server to proxy stream data

Closed this issue · 1 comments

My srs server is in network B, client is in network A.
Client use WHEP to get ICE data through http nginx, which can access network from A to B.
After setup SDP, stream data cannot be pulled because network A cannot acces network B through UDP directly.

I ask the question in deepseek, it provides the TURN answer. But I cannot find the 'turn_server' param in config. Open network access from clients to B is not easy, I can deply a TURN server in network A for clients easy access.

Is there a better solution?

Why SRS Does Not Support TURN Server

1. SRS is an SFU, Not a Peer-to-Peer System

From the documentation (trunk/3rdparty/srs-docs/doc/webrtc.md):

"TURN Server: Relay service that helps two browsers forward media data between them. This is a transparent forwarding service without data caching, so during multi-person meetings, browsers need to transfer N*N + N*(N-2) copies of data. It is generally used in very few communication scenarios, such as one-on-one.

SFU Server: Selective forwarding service with cached data on the server, allowing browsers to upload only one copy of data, which the server then replicates to other participants. SRS is an example of an SFU."

Key difference:

  • TURN: Helps two browsers/clients connect to each other (peer-to-peer relay)
  • SFU (SRS): Clients connect to the server, server forwards media between clients

2. SRS IS the Media Relay Point

In the SRS architecture:

+----------------+                        +---------+
+    Browser     +----<--Signaling----->--+   SRS   +
+ (like Chrome)  +----<----Media----->----+ (SFU)   +
+----------------+                        +---------+
  • Clients establish WebRTC connections directly with SRS
  • SRS receives media from publishers and forwards to subscribers
  • There is no peer-to-peer connection between clients
  • Therefore, there's no need for TURN to relay between peers

3. SRS Provides Alternative Solutions

Instead of TURN, SRS provides:

WebRTC over TCP (from trunk/conf/full.conf line 773):

# For WebRTC over TCP directly, not TURN, see https://github.com/ossrs/srs/issues/2852
tcp {
    enabled on;
    listen 8000;
}

Documentation explicitly states (line 268):

"Support directly transport over UDP or TCP, no dependency of TURN, no extra system and resource cost."

Summary

SRS doesn't support TURN because it doesn't need it. TURN is for peer-to-peer WebRTC scenarios (like video calls between browsers). SRS uses an SFU architecture where all clients connect to the server, making TURN unnecessary and redundant. The server itself provides the relay functionality that TURN would otherwise provide in a peer-to-peer setup.