.NET 用 Azure Communication Network Traversal クライアント ライブラリ - バージョン 1.0.0

Azure Communication Network Traversal を使用すると、低レベルの STUN および TURN サービスへのアクセスを提供することで、リアルタイムの通信シナリオとデータ転送シナリオのために、ピア間の高帯域幅、低待機時間の接続が可能になります。

ソースコード | 製品ドキュメント

作業の開始

パッケージをインストールする

NuGet を使用して .NET 用の Azure Communication Network Traversal クライアント ライブラリをインストールします。

dotnet add package Azure.Communication.NetworkTraversal --version 1.0.0

前提条件

このパッケージを使用するには、 Azure サブスクリプションCommunication Service リソース が必要です。

新しい Communication Service を作成するには、Azure PortalAzure PowerShell、または .NET 管理クライアント ライブラリを使用できます。

クライアントを認証する

ネットワーク クライアントは、 Azure Portal の Azure Communication Resources から取得した接続文字列を使用して認証できます。

// Get a connection string to our Azure Communication resource.
var connectionString = "<connection_string>";
var client = new CommunicationRelayClient(connectionString);

または、Azure Portal で Azure Communication Resources から取得したエンドポイントとアクセス キーを使用 することもできます

var endpoint = new Uri("https://my-resource.communication.azure.com");
var accessKey = "<access_key>";
var client = new CommunicationRelayClient(endpoint, new AzureKeyCredential(accessKey));

クライアントには、有効な Active Directory トークンを使用して認証するオプションもあります。

var endpoint = new Uri("https://my-resource.communication.azure.com");
TokenCredential tokenCredential = new DefaultAzureCredential();
var client = new CommunicationRelayClient(endpoint, tokenCredential);

主要な概念

CommunicationRelayClient には、STUN/TURN サーバー URL とアクセス用の資格情報を取得するための機能が用意されています。

スレッド セーフ

すべてのクライアント インスタンス メソッドがスレッド セーフであり、相互に独立していることを保証します (ガイドライン)。 これにより、クライアント インスタンスの再利用に関する推奨事項は、スレッド間でも常に安全になります。

その他の概念

クライアント オプション | 応答 | へのアクセス実行時間の長い操作 | エラーの | 処理診断 | あざける | クライアントの有効期間

ユーザーの Relay 構成の取得

Response<CommunicationRelayConfiguration> relayConfiguration = await client.GetRelayConfigurationAsync();
DateTimeOffset turnTokenExpiresOn = relayConfiguration.Value.ExpiresOn;
IList<CommunicationIceServer> iceServers = relayConfiguration.Value.IceServers;
Console.WriteLine($"Expires On: {turnTokenExpiresOn}");
foreach (CommunicationIceServer iceServer in iceServers)
{
    foreach (string url in iceServer.Urls)
    {
        Console.WriteLine($"ICE Server Url: {url}");
    }
    Console.WriteLine($"ICE Server Username: {iceServer.Username}");
    Console.WriteLine($"ICE Server Credential: {iceServer.Credential}");
    Console.WriteLine($"ICE Server RouteType: {iceServer.RouteType}");
}

指定した routeType を持つユーザーの Relay 構成の取得

Response<CommunicationRelayConfiguration> relayConfiguration = await client.GetRelayConfigurationAsync(user,RouteType.Nearest);
DateTimeOffset turnTokenExpiresOn = relayConfiguration.Value.ExpiresOn;
IList<CommunicationIceServer> iceServers = relayConfiguration.Value.IceServers;
Console.WriteLine($"Expires On: {turnTokenExpiresOn}");
foreach (CommunicationIceServer iceServer in iceServers)
{
    foreach (string url in iceServer.Urls)
    {
        Console.WriteLine($"ICE Server Url: {url}");
    }
    Console.WriteLine($"ICE Server Username: {iceServer.Username}");
    Console.WriteLine($"ICE Server Credential: {iceServer.Credential}");
    Console.WriteLine($"ICE Server Route Type: {iceServer.RouteType}");
}

トラブルシューティング

TODO

次のステップ

TODO

共同作成

このプロジェクトでは、共同作成と提案を歓迎しています。 ほとんどの共同作成では、共同作成者使用許諾契約書 (CLA) にご同意いただき、ご自身の共同作成内容を使用する権利を Microsoft に供与する権利をお持ちであり、かつ実際に供与することを宣言していただく必要があります。 詳細については、「 cla.microsoft.com」を参照してください。

このプロジェクトでは、Microsoft オープン ソースの倫理規定を採用しています。 詳しくは、「Code of Conduct FAQ (倫理規定についてよくある質問)」を参照するか、opencode@microsoft.com 宛てに質問またはコメントをお送りください。