title | keywords | author | ms.author | ms.date | ms.topic | ms.technology | ms.devlang | ms.service |
---|---|---|---|---|---|---|---|---|
Azure Communication Network Traversal client library for JavaScript |
Azure, javascript, SDK, API, @azure/communication-network-traversal, communication |
AriZavala2 |
arzavala |
03/11/2022 |
reference |
azure |
javascript |
azure-communication-services |
Azure Communication Network Traversal is managing tokens for Azure Communication Services.
It will provide TURN credentials to a user.
- An Azure subscription.
- An existing Communication Services resource. If you need to create the resource, you can use the Azure Portal, theAzure PowerShell, or the Azure CLI.
npm install @azure/communication-network-traversal
npm install @azure/communication-identity
To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our bundling documentation.
You can get a key and/or connection string from your Communication Services resource in Azure Portal. Once you have a key, you can authenticate the CommunicationRelayClient
with any of the following methods:
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);
import { DefaultAzureCredential } from "@azure/identity";
import { CommunicationRelayClient } from "@azure/communication-network-traversal";
const credential = new DefaultAzureCredential();
const client = new CommunicationRelayClient(ENDPOINT, credential);
If you use a key to initialize the client you will also need to provide the appropriate endpoint. You can get this endpoint from your Communication Services resource in Azure Portal.
import { CommunicationRelayClient } from "@azure/communication-network-traversal";
const client = new CommunicationRelayClient(CONNECTION_STRING);
import { CommunicationIdentityClient } from "@azure/communication-identity";
const client = new CommunicationIdentityClient(CONNECTION_STRING);
Use the createUser
method to create a new user.
const user = await client.createUser();
Use the getConfigurationRelay
method to get new TURN credentials providing a user
const config = await relayClient.getRelayConfiguration(user);
Also you can call the getConfigurationRelay
method without providing a user
const config = await relayClient.getRelayConfiguration();
You can specify a RouteType when calling getConfigurationRelay
const config = await relayClient.getRelayConfiguration(user, "nearest");
Please take a look at the samples directory for detailed examples on how to use this library.
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.