I am trying to use Azure Communication Services to create a user identity and then fetch relay configuration for network traversal.
Here is the code:
const { CommunicationIdentityClient } = require("@azure/communication-identity");
const { CommunicationRelayClient } = require("@azure/communication-network-traversal");;
const main = async () => {
console.log("Azure Communication Services - Relay Token Quickstart")
const connectionString = "CONNECTION STRING"
// Instantiate the identity client
const identityClient = new CommunicationIdentityClient(connectionString);
let identityResponse = await identityClient.createUser();
console.log(`nCreated an identity with ID: ${identityResponse.communicationUserId}`);
const relayClient = new CommunicationRelayClient(connectionString);
console.log("Getting relay configuration");
const config = await relayClient.getRelayConfiguration(identityResponse);
console.log("RelayConfig", config);
console.log("Printing entire thing ",config.iceServers);
};
main().catch((error) => {
console.log("Encountered and error");
console.log(error);
})
I got error as
<h2>Our services aren't available right now</h2><p>We're working to restore all services as soon as possible. Please check back soon.</p>
I searched on community forum and tried to implement the solution but got the same error.
- The SOLUTION described was:
**Solution:
"we cannot directly access the endpoint as a rest API endpoint there are extensions to it that we need to add so that we can reach the correct destination like in order to place a call using Azure communication services we need to use this endpoint.
{endpoint}/calling/callConnections?api-version=2021-08-30-preview
FYI this will not work until you provide the access token"**
- To which i modified the code as:
const { CommunicationIdentityClient } = require("@azure/communication-identity");
const axios = require('axios');
const main = async () => {
console.log("Azure Communication Services - Relay Token Quickstart");
const connectionString = "CONNECTION STRING";
// Extract endpoint and access key from the connection string
const endpoint = connectionString.match(/endpoint=(.*?);/)[1];
const accessKey = connectionString.match(/accesskey=(.*)/)[1];
// Instantiate the identity client
const identityClient = new CommunicationIdentityClient(connectionString);
try {
let identityResponse = await identityClient.createUser();
console.log(`nCreated an identity with ID: ${identityResponse.communicationUserId}`);
// Issue an access token for the created user
const tokenResponse = await identityClient.getToken(identityResponse, ["voip"]);
const accessToken = tokenResponse.token;
console.log(`nIssued an access token: ${accessToken}`);
// Construct the relay configuration request
const relayConfigUrl = `${endpoint}/networkTraversal/:issueRelayConfiguration?api-version=2022-03-01-preview`;
const response = await axios.post(relayConfigUrl, {
id: identityResponse.communicationUserId
}, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});
console.log("RelayConfig", response.data);
console.log("Printing entire thing ", response.data.iceServers);
} catch (error) {
console.log("Encountered an error");
console.log(error.response ? error.response.data : error.message);
}
};
main().catch((error) => {
console.log("Encountered an error");
console.log(error);
});
I got SAME error.
2
Answers
Thanks @Sampath. I solved the issue by incorporating twilio. We can also use AWS EC2 instance for it.
As per this DOC , the
@azure/communication-network-traversal
package is no longer maintained and the public preview of Azure Communication Services Network Traversal is ending.We need to add extensions to the endpoint in order to reach the desired destination. For example, we need to utilize this endpoint in order to place a call using Azure communication services. Otherwise, we cannot simply access the endpoint as a rest API endpoint.
{endpoint}/callConnections/calling?api-version=2021-08-30-preview
Just so you know, this won’t function until you give the access token.The following are steps to CallMedia play:
Create two variables and add collection variables for Call Setup:
Ensure you remove the trailing slash. For example,
https://contoso.communication.azure.com
.Call Setup with Cognitive Services: