Dela via


Azure Communication Network Traversal-klientbibliotek för JavaScript – version 1.0.0

Azure Communication Network Traversal hanterar token för Azure Communication Services.

Den tillhandahåller TURN-autentiseringsuppgifter till en användare.

Komma igång

Förutsättningar

Installation

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

Stöd för webbläsare

JavaScript-paket

Om du vill använda det här klientbiblioteket i webbläsaren måste du först använda en bundler. Mer information om hur du gör detta finns i vår paketeringsdokumentation.

Viktiga begrepp

Exempel

Autentisering

Du kan hämta en nyckel och/eller anslutningssträng från din Communication Services-resurs i Azure-portalen. När du har en nyckel kan du autentisera CommunicationRelayClient med någon av följande metoder:

Skapa KeyCredential med AzureKeyCredential innan klienten initieras

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

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

Använda en anslutningssträng

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

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

Använda en TokenCredential

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

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

Om du använder en nyckel för att initiera klienten måste du också ange lämplig slutpunkt. Du kan hämta den här slutpunkten från din Communication Services-resurs i Azure-portalen.

Användning

Skapa en instans av CommunicationRelayClient

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

const client = new CommunicationRelayClient(CONNECTION_STRING);

Skapa en instans av CommunicationIdentityClient för att skapa en användare

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

const client = new CommunicationIdentityClient(CONNECTION_STRING);

createUser Använd metoden för att skapa en ny användare.

const user = await client.createUser();

Hämta configurationRelay

getConfigurationRelay Använd metoden för att hämta nya TURN-autentiseringsuppgifter som ger en användare

const config = relayClient.getRelayConfiguration(user);

Du kan även anropa getConfigurationRelay metoden utan att tillhandahålla en användare

const config = relayClient.getRelayConfiguration();

Du kan ange en RouteType när du anropar getConfigurationRelay

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

Felsökning

Nästa steg

Ta en titt på exempelkatalogen för detaljerade exempel på hur du använder det här biblioteket.

Bidra

Om du vill bidra till det här biblioteket kan du läsa bidragsguiden för att lära dig mer om hur du skapar och testar koden.

Visningar