|
1 | 1 | ---
|
2 | 2 | title: include file
|
3 | 3 | description: include file
|
| 4 | +author: sloanster |
4 | 5 | services: azure-communication-services
|
5 | 6 | ms.date: 08/14/2023
|
6 | 7 | ms.topic: include
|
| 8 | +ms.author: chengyuanlai |
7 | 9 | ms.service: azure-communication-services
|
| 10 | +ms.subservice: calling |
| 11 | +ms.custom: mode-other |
8 | 12 | ---
|
9 | 13 |
|
10 |
| -## Force calling traffic to be proxied across your own server for iOS SDK |
| 14 | +[!INCLUDE [Public Preview](../../includes/public-preview-include-document.md)] |
11 | 15 |
|
12 |
| -In certain situations, it might be useful to have all your client traffic proxied to a server that you can control. When the SDK is initializing, you can provide the details of your servers that you would like the traffic to route to. This tutorial guides on how to have iOS SDK calling traffic be proxied to servers that you control. |
13 |
| - |
14 |
| ->[!IMPORTANT] |
15 |
| -> The proxy feature will be available in a future public preview version of the Calling SDK. |
16 | 16 | >[!IMPORTANT]
|
17 |
| -> The proxy feature will NOT be available for Teams Identities and Azure Communication Services Teams interop actions. |
| 17 | +> The proxy feature will NOT be available for Teams Identities and Azure Communication Services Teams interop actions. |
| 18 | +
|
| 19 | +## Proxy calling media traffic |
| 20 | + |
| 21 | +### What is a TURN server? |
| 22 | +Many times, establishing a network connection between two peers isn't straightforward. A direct connection might not work because of many reasons: firewalls with strict rules, peers sitting behind a private network, or computers running in a NAT (Network Address Translation) environment. To solve these network connection issues, you can use a TURN server. The term stands for Traversal Using Relays around NAT, and it's a protocol for relaying network traffic. STUN and TURN servers are the relay servers here. [Learn more about how Azure Communication Services mitigates network challenges by utilizing STUN and TURN](../../concepts/network-traversal.md). |
| 23 | + |
| 24 | +### Provide your TURN server details with the SDK |
| 25 | +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`. For more information how to set up a call, see [Azure Communication Services iOS SDK](../../quickstarts/voice-video-calling/get-started-with-video-calling.md?pivots=platform-ios) for the Quickstart on how to setup Voice and Video. |
| 26 | + |
| 27 | +```swift |
| 28 | +let callClientOptions = new CallClientOptions() |
| 29 | +let callNetworkOptions = new CallNetworkOptions() |
| 30 | + |
| 31 | +let iceServer = IceServer() |
| 32 | +iceServer.urls = ["turn:20.202.255.255"] |
| 33 | +iceServer.udpPort = 3478 |
| 34 | +iceServer.realm = "turn.azure.com" |
| 35 | +iceServer.username = "turnserver1username" |
| 36 | +iceServer.password = "turnserver1password" |
| 37 | + |
| 38 | +callNetworkOptions.iceServers = [iceServer] |
| 39 | + |
| 40 | +// Supply the network options when creating an instance of the CallClient |
| 41 | +callClientOptions.network = callNetworkOptions |
| 42 | +self.callClient = CallClient(options: callClientOptions); |
| 43 | + |
| 44 | +// ...continue normally with your SDK setup and usage. |
| 45 | +``` |
| 46 | + |
| 47 | +> [!IMPORTANT] |
| 48 | +> Note that if you have provided your TURN server details while initializing the `CallClient`, all the media traffic will <i>exclusively</i> flow through these TURN servers. Any other ICE candidates that are normally generated when creating a call won't be considered while trying to establish connectivity between peers i.e. only 'relay' candidates will be considered. To learn more about different types of Ice candidates click [here](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate/type). |
| 49 | +
|
| 50 | +> [!NOTE] |
| 51 | +> Currently, iOS SDK only supports <b>one IPv4 address</b> and <b>UDP</b> protocol for media proxy. Any URLs in non-ipv4 format will be ignored. When multiple URLs are provided, only the last one will be used by the SDK. |
| 52 | +> If UDP port is not provided, a default UDP port 3478 will be used. |
| 53 | +
|
| 54 | +> [!NOTE] |
| 55 | +> If any of the URLs provided are invalid, the `CallClient` initialization will fail and will throw errors accordingly. |
| 56 | +
|
| 57 | +### Set up a TURN server in Azure |
| 58 | +You can create a Linux virtual machine in the Azure portal using this [guide](/azure/virtual-machines/linux/quick-create-portal?tabs=ubuntu) and deploy a TURN server using [coturn](https://github.com/coturn/coturn). Coturn is a free and open source implementation of a TURN and STUN server for VoIP and WebRTC. |
| 59 | + |
| 60 | +Once you have 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/). |
| 61 | + |
18 | 62 | ## Proxy signaling traffic
|
19 | 63 |
|
20 |
| -To provide the URL of a proxy server, you need to pass it in as part of `CallClientOptions` through its property `CallNetworkOptions` while initializing the `CallClient`. For more details how to setup a call see [Azure Communication Services iOS SDK](../../quickstarts/voice-video-calling/get-started-with-video-calling.md?pivots=platform-ios)) for the Quickstart on how to setup Voice and Video. |
| 64 | +To provide the URL of a proxy server, you need to pass it in as part of `CallClientOptions` through its property `Network` while initializing the `CallClient`. For more information on how to set up a call, see [Azure Communication Services iOS SDK](../../quickstarts/voice-video-calling/get-started-with-video-calling.md?pivots=platform-ios) for the Quickstart on how to setup Voice and Video. |
21 | 65 |
|
22 | 66 | ```swift
|
23 | 67 | let callClientOptions = CallClientOptions()
|
24 | 68 | let callNetworkOptions = CallNetworkOptions()
|
25 |
| -callNetworkOptions.proxyAddress = proxyAddress |
26 |
| -callClientOptions.networkOptions = callNetworkOptions |
| 69 | +callNetworkOptions.proxyUrl = proxyUrl |
| 70 | +callClientOptions.network = callNetworkOptions |
27 | 71 | self.callClient = CallClient(options: callClientOptions)
|
| 72 | + |
28 | 73 | // ...continue normally with your SDK setup and usage.
|
29 | 74 | ```
|
| 75 | + |
| 76 | +### Setting up a signaling proxy server on Azure |
| 77 | +You can create a Linux virtual machine in the Azure portal and deploy an NGINX server on it using this guide - [Quickstart: Create a Linux virtual machine in the Azure portal](/azure/virtual-machines/linux/quick-create-portal?tabs=ubuntu). |
| 78 | + |
| 79 | +Here's an NGINX config that you could make use of for a quick spin up: |
| 80 | +``` |
| 81 | +events { |
| 82 | + multi_accept on; |
| 83 | + worker_connections 65535; |
| 84 | +} |
| 85 | +http { |
| 86 | + map $http_upgrade $connection_upgrade { |
| 87 | + default upgrade; |
| 88 | + '' close; |
| 89 | + } |
| 90 | + map $request_method $access_control_header { |
| 91 | + OPTIONS '*'; |
| 92 | + } |
| 93 | + server { |
| 94 | + listen <port_you_want_listen_on> ssl; |
| 95 | + ssl_certificate <path_to_your_ssl_cert>; |
| 96 | + ssl_certificate_key <path_to_your_ssl_key>; |
| 97 | + location ~* ^/(.*?\.(com|net)(?::[\d]+)?)/(.*)$ { |
| 98 | + if ($request_method = 'OPTIONS') { |
| 99 | + add_header Access-Control-Allow-Origin '*' always; |
| 100 | + add_header Access-Control-Allow-Credentials 'true' always; |
| 101 | + add_header Access-Control-Allow-Headers '*' always; |
| 102 | + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; |
| 103 | + add_header Access-Control-Max-Age 1728000; |
| 104 | + add_header Content-Type 'text/plain'; |
| 105 | + add_header Content-Length 0; |
| 106 | + return 204; |
| 107 | + } |
| 108 | + resolver 1.1.1.1; |
| 109 | + set $ups_host $1; |
| 110 | + set $r_uri $3; |
| 111 | + rewrite ^/.*$ /$r_uri break; |
| 112 | + proxy_set_header Host $ups_host; |
| 113 | + proxy_ssl_server_name on; |
| 114 | + proxy_ssl_protocols TLSv1.2; |
| 115 | + proxy_ssl_ciphers DEFAULT; |
| 116 | + proxy_set_header X-Real-IP $remote_addr; |
| 117 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 118 | + proxy_pass_header Authorization; |
| 119 | + proxy_pass_request_headers on; |
| 120 | + proxy_http_version 1.1; |
| 121 | + proxy_set_header Upgrade $http_upgrade; |
| 122 | + proxy_set_header Connection $connection_upgrade; |
| 123 | + proxy_set_header Proxy ""; |
| 124 | + proxy_set_header Access-Control-Allow-Origin $access_control_header; |
| 125 | + proxy_pass https://$ups_host; |
| 126 | + proxy_redirect https://$ups_host https://$host/$ups_host; |
| 127 | + proxy_intercept_errors on; |
| 128 | + error_page 301 302 307 = @process_redirect; |
| 129 | + error_page 400 405 = @process_error_response; |
| 130 | + } |
| 131 | + location @process_redirect { |
| 132 | + set $saved_redirect_location '$upstream_http_location'; |
| 133 | + resolver 1.1.1.1; |
| 134 | + proxy_pass $saved_redirect_location; |
| 135 | + add_header X-DBUG-MSG "301" always; |
| 136 | + } |
| 137 | + location @process_error_response { |
| 138 | + add_header Access-Control-Allow-Origin * always; |
| 139 | + } |
| 140 | + } |
| 141 | +} |
| 142 | +``` |
0 commit comments