Azure Communication Network Traversal client library for JavaScript - version 1.0.0
Azure Communication Network Traversal is managing tokens for Azure Communication Services.
It will provide TURN credentials to a user.
Getting started
Prerequisites
- 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.
Installing
npm install @azure/communication-network-traversal
npm install @azure/communication-identity
Browser support
JavaScript Bundle
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.
Key concepts
Examples
Authentication
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:
Create KeyCredential
with AzureKeyCredential
before initializing the client
import { AzureKeyCredential } from "@azure/core-auth";
import { CommunicationRelayClient } from "@azure/communication-network-traversal";
const credential = new AzureKeyCredential(KEY);
const client = new CommunicationRelayClient(ENDPOINT, credential);
Using a connection string
import { CommunicationRelayClient } from "@azure/communication-network-traversal";
const connectionString = `endpoint=ENDPOINT;accessKey=KEY`;
const client = new CommunicationRelayClient(connectionString);
Using a 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.
Usage
Creating an instance of CommunicationRelayClient
import { CommunicationRelayClient } from "@azure/communication-network-traversal";
const client = new CommunicationRelayClient(CONNECTION_STRING);
Creating an instance of CommunicationIdentityClient to create a user
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();
Getting the configurationRelay
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");
Troubleshooting
Next steps
Please take a look at the samples directory for detailed examples on how to use this library.
Contributing
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.
Related projects
Azure SDK for JavaScript