Azure Communication Network Traversal is managing tokens for Azure Communication Services.
It will provide TURN credentials to a user.
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:
KeyCredential
with AzureKeyCredential
before initializing the clientimport { 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);
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 = relayClient.getRelayConfiguration(user);
Also you can call the getConfigurationRelay
method without providing a user
const config = relayClient.getRelayConfiguration();
You can specify a RouteType when calling getConfigurationRelay
const config = 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.
Generated using TypeDoc