次の方法で共有


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

Azure Communication Network Traversal では、Azure Communication Servicesのトークンを管理しています。

ユーザーに TURN 資格情報が提供されます。

作業の開始

前提条件

[インストール中]

npm install @azure/communication-network-traversal
npm install @azure/communication-identity

ブラウザーのサポート

JavaScript バンドル

ブラウザーでこのクライアント ライブラリを使用するには、まず bundler を使用する必要があります。 これを行う方法の詳細については、 バンドルに関するドキュメントを参照してください。

主要な概念

認証

Azure Portal で Communication Services リソースからキーや接続文字列を取得できます。 キーを取得したら、次のいずれかの方法で を CommunicationRelayClient 認証できます。

クライアントをAzureKeyCredential初期化する前に を使用して を作成KeyCredentialする

import { AzureKeyCredential } from "@azure/core-auth";
import { CommunicationRelayClient } from "@azure/communication-network-traversal";

const credential = new AzureKeyCredential(KEY);
const client = new CommunicationRelayClient(ENDPOINT, credential);

接続文字列の使用

import { CommunicationRelayClient } from "@azure/communication-network-traversal";

const connectionString = `endpoint=ENDPOINT;accessKey=KEY`;
const client = new CommunicationRelayClient(connectionString);

TokenCredential の使用

import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationRelayClient } from "@azure/communication-network-traversal";

const credential = new DefaultAzureCredential();
const client = new CommunicationRelayClient(ENDPOINT, credential);

キーを使用してクライアントを初期化する場合は、適切なエンドポイントを指定する必要もあります。 このエンドポイントは、 Azure Portal の Communication Services リソースから取得できます。

使用

CommunicationRelayClient のインスタンスの作成

import { CommunicationRelayClient } from "@azure/communication-network-traversal";

const client = new CommunicationRelayClient(CONNECTION_STRING);

CommunicationIdentityClient のインスタンスを作成してユーザーを作成する

import { CommunicationIdentityClient } from "@azure/communication-identity";

const client = new CommunicationIdentityClient(CONNECTION_STRING);

メソッドを createUser 使用して新しいユーザーを作成します。

const user = await client.createUser();

構成の取得Relay

メソッドを getConfigurationRelay 使用して、ユーザーに提供される新しい TURN 資格情報を取得する

const config = relayClient.getRelayConfiguration(user);

また、ユーザーを getConfigurationRelay 指定せずに メソッドを呼び出すこともできます

const config = relayClient.getRelayConfiguration();

を呼び出すときに RouteType を指定できます。 getConfigurationRelay

const config = relayClient.getRelayConfiguration(user, "nearest");

トラブルシューティング

次のステップ

このライブラリの使用方法の詳細な例については、 サンプル ディレクトリを参照してください。

共同作成

このライブラリに投稿する場合、コードをビルドしてテストする方法の詳細については、投稿ガイドを参照してください。

インプレッション数