Share via


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 번들

브라우저에서 이 클라이언트 라이브러리를 사용하려면 먼저 번들러를 사용해야 합니다. 이 작업을 수행하는 방법에 대한 자세한 내용은 번들링 설명서를 참조하세요.

주요 개념

예제

인증

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();

configurationRelay 가져오기

메서드를 getConfigurationRelay 사용하여 사용자에게 제공하는 새 TURN 자격 증명 가져오기

const config = relayClient.getRelayConfiguration(user);

또한 사용자를 제공하지 않고 메서드를 호출 getConfigurationRelay 할 수 있습니다.

const config = relayClient.getRelayConfiguration();

를 호출할 때 RouteType을 지정할 수 있습니다. getConfigurationRelay

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

문제 해결

다음 단계

이 라이브러리를 사용하는 방법에 대한 자세한 예제는 샘플 디렉터리를 참조하세요.

참여

이 라이브러리에 기여하려면 기여 가이드 를 참조하여 코드를 빌드하고 테스트하는 방법에 대해 자세히 알아보세요.

Impressions