Skip to content

Commit 6a8a9f8

Browse files
authored
Create tutorial-proxy-calling.md
1 parent 97252d2 commit 6a8a9f8

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Tutorial - Proxy your ACS calling traffic across your own servers
3+
titleSuffix: An Azure Communication Services tutorial
4+
description: Learn how to have your media and signaling traffic be proxied to servers that you can control
5+
author: sloanster
6+
services: azure-communication-services
7+
8+
ms.author: micahvivion
9+
ms.date: 04/18/2023
10+
ms.topic: quickstart
11+
ms.service: azure-communication-services
12+
ms.subservice: calling
13+
ms.custom: mode-other
14+
---
15+
16+
# Setup calling to be proxyed across your own servers.
17+
18+
In certain situations it might be useful to have all your client traffic be proxyed to a TURN server that you can control. This tutorial will walk you through the process to ena. When the SDK is initializing you can provide the details of your TURN servers that you would like the traffic to route to. When this is enabled all the media traffic (audio/video/screen sharing) will flow through the provided TURN servers instead of the Azure Communication Services defaults. Once your provide your TURN server details while initializing the `CallClient`, all the calls to and from this `CallClient` will be using the provided TURN servers. Below is a guide on how to do provide your TURN configurations to the WebJS SDK.
19+
20+
>[!IMPORTANT]
21+
> The custom proxy feature is available starting on the public preview version [1.13.0-beta.4](https://www.npmjs.com/package/@azure/communication-calling/v/1.13.0-beta.4) of the Calling SDK. Please ensure that you use this or a newer SDK when trying to use this feature. This quickstart uses the Azure Communication Services Calling SDK version greater than `1.13.0`.
22+
23+
[!INCLUDE [Public Preview](../../../includes/public-preview-include-document.md)]
24+
25+
## What is a STUN/TURN server?
26+
Many times establishing connection between two peers is not straightforward and a direct connection will not work because of many reasons - firewalls with strict rules, peers sitting behind a private network, etc. In many situations your device does not have a public IP address to establish a connection straightaway and so relaying data via a relay server, that is usually known to both peers, is a way to allow this connection to happen. The WebRTC ICE (Interactive Connectivity Establishment) framework helps make this happen. STUN and TURN servers are the relay servers here. See [Network Traversal Concepts](../../../../concepts/network-traversal.md) for more details on how ACS mitigates network challenges with STUN and TURN.
27+
28+
## Providing your TURN servers to the SDK
29+
To provide the details of your TURN servers, you need to pass details of what TURN server to use as part of `CallClientOptions` while initializing the `CallClient`. See the quickstart on how to setup Voice and Video calling using the Web SDK at - [Azure Communication Services Web SDK](../get-started-with-video-calling.md?pivots=platform-web)).
30+
31+
```js
32+
import { CallClient } from '@azure/communication-calling';
33+
34+
const myTurn1 = {
35+
urls: [
36+
'turn:turn.azure.com:3478?transport=udp',
37+
'turn:turn1.azure.com:3478?transport=udp',
38+
],
39+
username: 'turnserver1username',
40+
credential: 'turnserver1credentialorpass'
41+
};
42+
43+
const myTurn2 = {
44+
urls: [
45+
'turn:20.202.255.255:3478',
46+
'turn:20.202.255.255:3478?transport=tcp',
47+
],
48+
username: 'turnserver2username',
49+
credential: 'turnserver2credentialorpass'
50+
};
51+
52+
// While you are creating an instance of the CallClient (the entry point of the SDK):
53+
const callClient = new CallClient({
54+
networkConfiguration: {
55+
turn: {
56+
iceServers: [
57+
myTurn1,
58+
myTurn2
59+
]
60+
}
61+
}
62+
});
63+
64+
// ...continue normally with your SDK setup and usage.
65+
```
66+
67+
> [!IMPORTANT]
68+
> Note that if you've provided your TURN server details while initializing the `CallClient`, all the media traffic will <i>exclusively</i> flow through these TURN servers. That means, other ice candidates will not be considered while trying to establish connectivity between peers i.e. only 'relay' candidates will be considered. More information on types of ice candidates can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate/type). This behaviour might change in the future versions of the SDK.
69+
70+
> [!NOTE]
71+
> If the '?transport' query parameter is not present as part of the TURN url or is not one of these values - 'udp', 'tcp', 'tls', the default will behaviour will be UDP.
72+
73+
> [!NOTE]
74+
> If any of the URLs provided are invalid or don't have one of these schemas - 'turn:', 'turns:', 'stun:', the `CallClient` initialization will fail and will throw errors accordingly. The error messages thrown should help you troubleshoot if you run into issues.
75+
76+
The API reference for the `CallClientOptions` object, and the `networkConfiguration` property within it can be found here - [CallClientOptions](https://learn.microsoft.com/en-gb/javascript/api/azure-communication-services/@azure/communication-calling/callclientoptions?view=azure-communication-services-js).
77+
78+
## Setting up a TURN server in Azure
79+
You can create a Linux virtual machine in the Azure portal using this guide - [Quickstart: Create a Linux virtual machine in the Azure portal](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-portal?tabs=ubuntu), and deploy a TURN server using [coturn](https://github.com/coturn/coturn), a free and open source implementation of a TURN and STUN server for VoIP and WebRTC.
80+
Best spot to start from - [coturn turnserver README](https://github.com/coturn/coturn/blob/master/README.turnserver)
81+
82+
Once you've setup a TURN server, you can test it using the WebRTC Trickle ICE page - [Trickle ICE](https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/).
83+
Add your server details here, select 'relay' in the ICE options section and click on 'Gather candidates':

0 commit comments

Comments
 (0)