Skip to content

Commit a6bdd89

Browse files
sipsorceryCopilot
andauthored
Adds a STUNClient and extension to make consuming the RTP server reflexive address more convenient (#1460)
* Adds a STUNClient and extension to make consuming the RTP server reflexive address more convenient. * Update src/net/RTP/RTPSession.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/net/STUN/STUNClient.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Use the timeout secodns in the stun client extension. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e4bc852 commit a6bdd89

File tree

17 files changed

+474
-1034
lines changed

17 files changed

+474
-1034
lines changed

examples/SIPExamples/SIPExamples.sln

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SIPCallServer", "SIPCallSer
4747
EndProject
4848
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SIPCloudCallServer", "SIPCloudCallServer\SIPCloudCallServer.csproj", "{AC215797-8B94-2D46-A603-D4EAC8C8604A}"
4949
EndProject
50-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserAgentClientWithStun", "UserAgentClientWithStun\UserAgentClientWithStun.csproj", "{DF234766-1556-47E7-E748-2A7441854647}"
51-
EndProject
52-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserAgentServerWithStun", "UserAgentServerWithStun\UserAgentServerWithStun.csproj", "{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}"
53-
EndProject
5450
Global
5551
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5652
Debug|Any CPU = Debug|Any CPU
@@ -325,30 +321,6 @@ Global
325321
{AC215797-8B94-2D46-A603-D4EAC8C8604A}.Release|x64.Build.0 = Release|Any CPU
326322
{AC215797-8B94-2D46-A603-D4EAC8C8604A}.Release|x86.ActiveCfg = Release|Any CPU
327323
{AC215797-8B94-2D46-A603-D4EAC8C8604A}.Release|x86.Build.0 = Release|Any CPU
328-
{DF234766-1556-47E7-E748-2A7441854647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
329-
{DF234766-1556-47E7-E748-2A7441854647}.Debug|Any CPU.Build.0 = Debug|Any CPU
330-
{DF234766-1556-47E7-E748-2A7441854647}.Debug|x64.ActiveCfg = Debug|Any CPU
331-
{DF234766-1556-47E7-E748-2A7441854647}.Debug|x64.Build.0 = Debug|Any CPU
332-
{DF234766-1556-47E7-E748-2A7441854647}.Debug|x86.ActiveCfg = Debug|Any CPU
333-
{DF234766-1556-47E7-E748-2A7441854647}.Debug|x86.Build.0 = Debug|Any CPU
334-
{DF234766-1556-47E7-E748-2A7441854647}.Release|Any CPU.ActiveCfg = Release|Any CPU
335-
{DF234766-1556-47E7-E748-2A7441854647}.Release|Any CPU.Build.0 = Release|Any CPU
336-
{DF234766-1556-47E7-E748-2A7441854647}.Release|x64.ActiveCfg = Release|Any CPU
337-
{DF234766-1556-47E7-E748-2A7441854647}.Release|x64.Build.0 = Release|Any CPU
338-
{DF234766-1556-47E7-E748-2A7441854647}.Release|x86.ActiveCfg = Release|Any CPU
339-
{DF234766-1556-47E7-E748-2A7441854647}.Release|x86.Build.0 = Release|Any CPU
340-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
341-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
342-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Debug|x64.ActiveCfg = Debug|Any CPU
343-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Debug|x64.Build.0 = Debug|Any CPU
344-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Debug|x86.ActiveCfg = Debug|Any CPU
345-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Debug|x86.Build.0 = Debug|Any CPU
346-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
347-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Release|Any CPU.Build.0 = Release|Any CPU
348-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Release|x64.ActiveCfg = Release|Any CPU
349-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Release|x64.Build.0 = Release|Any CPU
350-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Release|x86.ActiveCfg = Release|Any CPU
351-
{C130FDC0-A4DA-57DC-0E96-C9A4E36DDFCB}.Release|x86.Build.0 = Release|Any CPU
352324
EndGlobalSection
353325
GlobalSection(SolutionProperties) = preSolution
354326
HideSolutionNode = FALSE

examples/SIPExamples/UserAgentClient/Program.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//
1414
// Usage Examples:
1515
// set TURN_URL=turn:your.turn.server;user;password
16+
// set STUN_URL=stun:stun.l.google.com:19302
1617
// dotnet run -- 127.0.0.1:5080
1718
//
1819
// Author(s):
@@ -46,6 +47,7 @@ namespace demo;
4647
class Program
4748
{
4849
private const string TURN_SERVER_URL_ENV_VAR = "TURN_URL";
50+
private const string STUN_SERVER_URL_ENV_VAR = "STUN_URL";
4951
private static readonly string DEFAULT_DESTINATION_SIP_URI = "sip:music@iptel.org";
5052
private const int TURN_ALLOCATION_TIMEOUT_SECONDS = 5;
5153

@@ -65,10 +67,13 @@ static async Task Main(string[] args)
6567
Log = AddConsoleLogger(LogEventLevel.Debug);
6668

6769
var turnServerUrl = Environment.GetEnvironmentVariable(TURN_SERVER_URL_ENV_VAR);
68-
6970
TurnClient turnClient = !string.IsNullOrWhiteSpace(turnServerUrl) ?
7071
new TurnClient(turnServerUrl) : null;
7172

73+
var stunServerUrl = Environment.GetEnvironmentVariable(STUN_SERVER_URL_ENV_VAR);
74+
STUNClient stunClient = !string.IsNullOrWhiteSpace(stunServerUrl) ?
75+
new STUNClient(stunServerUrl) : null;
76+
7277
SIPURI callUri = SIPURI.ParseSIPURI(DEFAULT_DESTINATION_SIP_URI);
7378
if (args?.Length > 0)
7479
{
@@ -105,6 +110,10 @@ static async Task Main(string[] args)
105110
{
106111
await rtpSession.AudioStream.UseTurn(rtpSession, turnClient, default, TURN_ALLOCATION_TIMEOUT_SECONDS);
107112
}
113+
else if (stunClient != null)
114+
{
115+
await rtpSession.AudioStream.UseStun(stunClient, default, Log);
116+
}
108117

109118
var offerSDP = rtpSession.CreateOffer(preferIPv6 ? IPAddress.IPv6Any : IPAddress.Any);
110119

examples/SIPExamples/UserAgentClientWithStun/Program.cs

Lines changed: 0 additions & 287 deletions
This file was deleted.

examples/SIPExamples/UserAgentClientWithStun/UserAgentClientWithStun.csproj

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)