Skip to content

Commit 02f27a2

Browse files
authored
Updating Azure.Communication.NetworkTraversal to new API version 2021-06-21-preview (Azure#22578)
1 parent ede3703 commit 02f27a2

31 files changed

+629
-392
lines changed

sdk/communication/Azure.Communication.NetworkTraversal/CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Release History
22

3-
## 1.0.0-beta.2 (Unreleased)
3+
## 1.0.0-beta.2 (2021-07-13)
44

5+
- Renamed `CommunicationTurnServer` to `CommunicationIceServer`
6+
- Renamed field `turnServers` to `iceServers` in `CommunicationRelayConfiguration`
7+
- Renamed `IssueCredentials[Async]` to `IssueRelayConfiguration[Async]`
58

69
## 1.0.0-beta.1 (2021-05-24)
710

sdk/communication/Azure.Communication.NetworkTraversal/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ We guarantee that all client instance methods are thread-safe and independent of
6565

6666
## Examples
6767

68-
## Generating TURN credentials for a user
68+
## Getting a Relay Configuration for a user
6969

7070
```C# Snippet:GetRelayConfigurationAsync
71-
Response<CommunicationRelayConfiguration> turnTokenResponse = await client.GetRelayConfigurationAsync(user);
72-
DateTimeOffset turnTokenExpiresOn = turnTokenResponse.Value.ExpiresOn;
73-
IReadOnlyList<CommunicationTurnServer> turnServers = turnTokenResponse.Value.TurnServers;
71+
Response<CommunicationRelayConfiguration> relayConfiguration = await client.GetRelayConfigurationAsync(user);
72+
DateTimeOffset turnTokenExpiresOn = relayConfiguration.Value.ExpiresOn;
73+
IReadOnlyList<CommunicationIceServer> iceServers = relayConfiguration.Value.IceServers;
7474
Console.WriteLine($"Expires On: {turnTokenExpiresOn}");
75-
foreach (CommunicationTurnServer turnServer in turnServers)
75+
foreach (CommunicationIceServer iceServer in iceServers)
7676
{
77-
foreach (string url in turnServer.Urls)
77+
foreach (string url in iceServer.Urls)
7878
{
79-
Console.WriteLine($"TURN Url: {url}");
79+
Console.WriteLine($"ICE Server Url: {url}");
8080
}
81-
Console.WriteLine($"TURN Username: {turnServer.Username}");
82-
Console.WriteLine($"TURN Credential: {turnServer.Credential}");
81+
Console.WriteLine($"ICE Server Username: {iceServer.Username}");
82+
Console.WriteLine($"ICE Server Credential: {iceServer.Credential}");
8383
}
8484
```
8585

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
namespace Azure.Communication.NetworkTraversal
22
{
3+
public partial class CommunicationIceServer
4+
{
5+
internal CommunicationIceServer() { }
6+
public string Credential { get { throw null; } }
7+
public System.Collections.Generic.IReadOnlyList<string> Urls { get { throw null; } }
8+
public string Username { get { throw null; } }
9+
}
310
public partial class CommunicationRelayClient
411
{
512
protected CommunicationRelayClient() { }
@@ -12,28 +19,21 @@ public CommunicationRelayClient(System.Uri endpoint, Azure.Core.TokenCredential
1219
}
1320
public partial class CommunicationRelayClientOptions : Azure.Core.ClientOptions
1421
{
15-
public CommunicationRelayClientOptions(Azure.Communication.NetworkTraversal.CommunicationRelayClientOptions.ServiceVersion version = Azure.Communication.NetworkTraversal.CommunicationRelayClientOptions.ServiceVersion.V2021_02_22_preview1) { }
22+
public CommunicationRelayClientOptions(Azure.Communication.NetworkTraversal.CommunicationRelayClientOptions.ServiceVersion version = Azure.Communication.NetworkTraversal.CommunicationRelayClientOptions.ServiceVersion.V2021_06_21_preview) { }
1623
public enum ServiceVersion
1724
{
18-
V2021_02_22_preview1 = 1,
25+
V2021_06_21_preview = 1,
1926
}
2027
}
2128
public partial class CommunicationRelayConfiguration
2229
{
2330
internal CommunicationRelayConfiguration() { }
2431
public System.DateTimeOffset ExpiresOn { get { throw null; } }
25-
public System.Collections.Generic.IReadOnlyList<Azure.Communication.NetworkTraversal.CommunicationTurnServer> TurnServers { get { throw null; } }
26-
}
27-
public partial class CommunicationTurnServer
28-
{
29-
internal CommunicationTurnServer() { }
30-
public string Credential { get { throw null; } }
31-
public System.Collections.Generic.IReadOnlyList<string> Urls { get { throw null; } }
32-
public string Username { get { throw null; } }
32+
public System.Collections.Generic.IReadOnlyList<Azure.Communication.NetworkTraversal.CommunicationIceServer> IceServers { get { throw null; } }
3333
}
3434
public static partial class NetworkTraversalModelFactory
3535
{
36-
public static Azure.Communication.NetworkTraversal.CommunicationRelayConfiguration CommunicationRelayConfiguration(System.DateTimeOffset expiresOn = default(System.DateTimeOffset), System.Collections.Generic.IEnumerable<Azure.Communication.NetworkTraversal.CommunicationTurnServer> turnServers = null) { throw null; }
37-
public static Azure.Communication.NetworkTraversal.CommunicationTurnServer CommunicationTurnServer(System.Collections.Generic.IEnumerable<string> urls = null, string username = null, string credential = null) { throw null; }
36+
public static Azure.Communication.NetworkTraversal.CommunicationIceServer CommunicationIceServer(System.Collections.Generic.IEnumerable<string> urls = null, string username = null, string credential = null) { throw null; }
37+
public static Azure.Communication.NetworkTraversal.CommunicationRelayConfiguration CommunicationRelayConfiguration(System.DateTimeOffset expiresOn = default(System.DateTimeOffset), System.Collections.Generic.IEnumerable<Azure.Communication.NetworkTraversal.CommunicationIceServer> iceServers = null) { throw null; }
3838
}
3939
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- csharp
5+
products:
6+
- azure
7+
- azure-communication-services
8+
name: Azure Communication NetworkTraversal samples for .NET
9+
description: Samples for the Azure.Communication.NetworkTraversal client library
10+
---
11+
12+
# Azure Communication NetworkTraversal SDK samples
13+
14+
Azure Communication NetworkTraversal is a client library that is used for fetching relay configuration information for STUN and TURN services.
15+
16+
To get started you will need to have an Azure Subscription. Once you have this you can go into the Azure portal and create Azure Communication Services resource. The page will give you necessary information to be able to use the sample codes here such as connections string, shared access key, etc.
17+
18+
This client library allows for the following operations:
19+
- Fetch information that allow the bearers to access a TURN server for data relay.
20+
21+
You can find samples for each of these functions below.
22+
- Fetch relay information [synchronously][sample_relay] or [asynchronously][sample_relay_async]
23+
24+
<!-- LINKS -->
25+
[sample_relay]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/communication/Azure.Communication.NetworkTraversal/samples/Sample1_CommunicationRelayClient.md
26+
[sample_relay_async]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/communication/Azure.Communication.NetworkTraversal/samples/Sample1_CommunicationRelayClientAsync.md
27+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Obtain a Relay Configuration for Network Traversal from Azure Communication Services
2+
3+
This sample demonstrates how to obtain a relay configuration for network traversal from Azure Communication Services. You can use this configuration for STUN/TURN relay scenarios.
4+
5+
To get started you'll need an Azure Communication Services resource. See the README for prerequisites and instructions.
6+
7+
## Create a `CommunicationRelayClient`
8+
9+
To create a new `CommunicationRelayClient` you need a connection string to the Azure Communication Services resource that you can get from the Azure Portal once you have created the resource.
10+
11+
You can set `connectionString` based on an environment variable, a configuration setting, or any way that works for your application.
12+
13+
```C# Snippet:CreateCommunicationRelayClient
14+
// Get a connection string to our Azure Communication resource.
15+
var connectionString = "<connection_string>";
16+
var client = new CommunicationRelayClient(connectionString);
17+
```
18+
19+
Or alternatively using the endpoint and access key acquired from an Azure Communication Resources in the [Azure Portal][azure_portal].
20+
21+
```C# Snippet:CreateCommunicationRelayFromAccessKey
22+
var endpoint = new Uri("https://my-resource.communication.azure.com");
23+
var accessKey = "<access_key>";
24+
var client = new CommunicationRelayClient(endpoint, new AzureKeyCredential(accessKey));
25+
```
26+
27+
Clients also have the option to authenticate using a valid Active Directory token.
28+
29+
```C# Snippet:CreateCommunicationRelayFromToken
30+
var endpoint = new Uri("https://my-resource.communication.azure.com");
31+
TokenCredential tokenCredential = new DefaultAzureCredential();
32+
var client = new CommunicationRelayClient(endpoint, tokenCredential);
33+
```
34+
35+
## Get Relay Configuration
36+
37+
The example code snippet below shows how to get a relay configuration for an Azure Communication user. For examples on how to create a Azure Communication user, view the [Identity Samples][identity_samples].
38+
A configuration is returned for the user. Each configuration consists of a URL for a TURN server, its corresponding username and a credential.
39+
40+
Every relay configuration has an expiry date and time stamped on it, indicating when the set of TURN credentials will no longer be accepted. Once the credentials have expired, you can renew the token by calling the same method.
41+
42+
```C# Snippet:GetRelayConfiguration
43+
Response<CommunicationRelayConfiguration> relayConfiguration = client.GetRelayConfiguration(user);
44+
DateTimeOffset turnTokenExpiresOn = relayConfiguration.Value.ExpiresOn;
45+
IReadOnlyList<CommunicationIceServer> iceServers = relayConfiguration.Value.IceServers;
46+
Console.WriteLine($"Expires On: {turnTokenExpiresOn}");
47+
foreach (CommunicationIceServer iceServer in iceServers)
48+
{
49+
foreach (string url in iceServer.Urls)
50+
{
51+
Console.WriteLine($"ICE Server Url: {url}");
52+
}
53+
Console.WriteLine($"ICE Server Username: {iceServer.Username}");
54+
Console.WriteLine($"ICE Server Credential: {iceServer.Credential}");
55+
}
56+
```
57+
58+
<!-- LINKS -->
59+
60+
[azure_portal]: https://portal.azure.com
61+
[identity_samples]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/communication/Azure.Communication.Identity/samples
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Obtain a Relay Configuration for Network Traversal from Azure Communication Services
2+
3+
This sample demonstrates how to obtain a relay configuration for network traversal from Azure Communication Services. You can use this configuration for STUN/TURN relay scenarios.
4+
5+
To get started you'll need an Azure Communication Services resource. See the README for prerequisites and instructions.
6+
7+
## Create a `CommunicationRelayClient`
8+
9+
To create a new `CommunicationRelayClient` you need a connection string to the Azure Communication Services resource that you can get from the Azure Portal once you have created the resource.
10+
11+
You can set `connectionString` based on an environment variable, a configuration setting, or any way that works for your application.
12+
13+
```C# Snippet:CreateCommunicationRelayClientAsync
14+
// Get a connection string to our Azure Communication resource.
15+
var connectionString = "<connection_string>";
16+
var client = new CommunicationRelayClient(connectionString);
17+
```
18+
19+
Or alternatively using the endpoint and access key acquired from an Azure Communication Resources in the [Azure Portal][azure_portal].
20+
21+
```C# Snippet:CreateCommunicationRelayFromAccessKey
22+
var endpoint = new Uri("https://my-resource.communication.azure.com");
23+
var accessKey = "<access_key>";
24+
var client = new CommunicationRelayClient(endpoint, new AzureKeyCredential(accessKey));
25+
```
26+
27+
Clients also have the option to authenticate using a valid Active Directory token.
28+
29+
```C# Snippet:CreateCommunicationRelayFromToken
30+
var endpoint = new Uri("https://my-resource.communication.azure.com");
31+
TokenCredential tokenCredential = new DefaultAzureCredential();
32+
var client = new CommunicationRelayClient(endpoint, tokenCredential);
33+
```
34+
35+
## Get Relay Configuration
36+
37+
The example code snippet below shows how to get a relay configuration for an Azure Communication user. For examples on how to create a Azure Communication user, view the [Identity Samples][identity_samples].
38+
A configuration is returned for the user. Each configuration consists of a URL for a TURN server, its corresponding username and a credential.
39+
40+
Every relay configuration has an expiry date and time stamped on it, indicating when the set of TURN credentials will no longer be accepted. Once the credentials have expired, you can renew the token by calling the same method.
41+
42+
```C# Snippet:GetRelayConfigurationAsync
43+
Response<CommunicationRelayConfiguration> relayConfiguration = await client.GetRelayConfigurationAsync(user);
44+
DateTimeOffset turnTokenExpiresOn = relayConfiguration.Value.ExpiresOn;
45+
IReadOnlyList<CommunicationIceServer> iceServers = relayConfiguration.Value.IceServers;
46+
Console.WriteLine($"Expires On: {turnTokenExpiresOn}");
47+
foreach (CommunicationIceServer iceServer in iceServers)
48+
{
49+
foreach (string url in iceServer.Urls)
50+
{
51+
Console.WriteLine($"ICE Server Url: {url}");
52+
}
53+
Console.WriteLine($"ICE Server Username: {iceServer.Username}");
54+
Console.WriteLine($"ICE Server Credential: {iceServer.Credential}");
55+
}
56+
```
57+
58+
<!-- LINKS -->
59+
60+
[azure_portal]: https://portal.azure.com
61+
[identity_samples]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/communication/Azure.Communication.Identity/samples

sdk/communication/Azure.Communication.NetworkTraversal/src/CommunicationRelayClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected CommunicationRelayClient()
9090
RestClient = null;
9191
}
9292

93-
/// <summary>Gets a TURN credential for a <see cref="CommunicationUserIdentifier"/>.</summary>
93+
/// <summary>Gets a Relay Configuration for a <see cref="CommunicationUserIdentifier"/>.</summary>
9494
/// <param name="communicationUser">The <see cref="CommunicationUserIdentifier"/> for whom to issue a token.</param>
9595
/// <param name="cancellationToken">The cancellation token to use.</param>
9696
/// <exception cref="RequestFailedException">The server returned an error.</exception>
@@ -100,7 +100,7 @@ public virtual Response<CommunicationRelayConfiguration> GetRelayConfiguration(C
100100
scope.Start();
101101
try
102102
{
103-
return RestClient.IssueTurnCredentials(communicationUser.Id, cancellationToken);
103+
return RestClient.IssueRelayConfiguration(communicationUser.Id, cancellationToken);
104104
}
105105
catch (Exception ex)
106106
{
@@ -109,7 +109,7 @@ public virtual Response<CommunicationRelayConfiguration> GetRelayConfiguration(C
109109
}
110110
}
111111

112-
/// <summary>Asynchronously gets a TURN credential for a <see cref="CommunicationUserIdentifier"/>.</summary>
112+
/// <summary>Asynchronously gets a Relay Configuration for a <see cref="CommunicationUserIdentifier"/>.</summary>
113113
/// <param name="communicationUser">The <see cref="CommunicationUserIdentifier"/> for whom to issue a token.</param>
114114
/// <param name="cancellationToken">The cancellation token to use.</param>
115115
public virtual async Task<Response<CommunicationRelayConfiguration>> GetRelayConfigurationAsync(CommunicationUserIdentifier communicationUser, CancellationToken cancellationToken = default)
@@ -118,7 +118,7 @@ public virtual async Task<Response<CommunicationRelayConfiguration>> GetRelayCon
118118
scope.Start();
119119
try
120120
{
121-
return await RestClient.IssueTurnCredentialsAsync(communicationUser.Id, cancellationToken).ConfigureAwait(false);
121+
return await RestClient.IssueRelayConfigurationAsync(communicationUser.Id, cancellationToken).ConfigureAwait(false);
122122
}
123123
catch (Exception ex)
124124
{

sdk/communication/Azure.Communication.NetworkTraversal/src/CommunicationRelayClientOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class CommunicationRelayClientOptions : ClientOptions
1414
/// <summary>
1515
/// The latest version of the networking service.
1616
/// </summary>
17-
internal const ServiceVersion LatestVersion = ServiceVersion.V2021_02_22_preview1;
17+
internal const ServiceVersion LatestVersion = ServiceVersion.V2021_06_21_preview;
1818

1919
internal string ApiVersion { get; }
2020

@@ -25,7 +25,7 @@ public CommunicationRelayClientOptions(ServiceVersion version = LatestVersion)
2525
{
2626
ApiVersion = version switch
2727
{
28-
ServiceVersion.V2021_02_22_preview1 => "2021-02-22-preview1",
28+
ServiceVersion.V2021_06_21_preview => "2021-06-21-preview",
2929
_ => throw new ArgumentOutOfRangeException(nameof(version)),
3030
};
3131
}
@@ -37,9 +37,9 @@ public enum ServiceVersion
3737
{
3838
#pragma warning disable CA1707 // Identifiers should not contain underscores
3939
/// <summary>
40-
/// The V2021_02_22_preview1 of the networking service.
40+
/// The V2021_06_21_preview of the networking service.
4141
/// </summary>
42-
V2021_02_22_preview1 = 1,
42+
V2021_06_21_preview = 1,
4343
#pragma warning restore CA1707 // Identifiers should not contain underscores
4444
}
4545
}

0 commit comments

Comments
 (0)