azure.communication.networktraversal.aio package

class azure.communication.networktraversal.aio.CommunicationRelayClient(endpoint: str, credential: AsyncTokenCredential, **kwargs)[source]

Azure Communication Services Network Traversal client.

Parameters
  • endpoint (str) – The endpoint url for Azure Communication Service resource.

  • credential (AsyncTokenCredential) – The AsyncTokenCredential we use to authenticate against the service.

Example:

: utf-8

-------------------------------------------------------------------
ght (c) Microsoft Corporation. All rights reserved.
ed under the MIT License. See License.txt in the project root for
e information.
--------------------------------------------------------------------


twork_traversal_samples_async.py
ION:
e samples demonstrate creating a user, issuing a token, revoking a token and deleting a user.


on network_traversal_samples.py
the environment variables with your own values before running the sample:
OMMUNICATION_SAMPLES_CONNECTION_STRING - the connection string in your ACS resource
ZURE_CLIENT_ID - the client ID of your active directory application
ZURE_CLIENT_SECRET - the secret of your active directory application
ZURE_TENANT_ID - the tenant ID of your active directory application

s
syncio
re.communication.networktraversal._shared.utils import parse_connection_str

mmunicationRelayClientSamples(object):

__init__(self):
self.connection_string = os.getenv('COMMUNICATION_SAMPLES_CONNECTION_STRING')
self.client_id = os.getenv('AZURE_CLIENT_ID')
self.client_secret = os.getenv('AZURE_CLIENT_SECRET')
self.tenant_id = os.getenv('AZURE_TENANT_ID')

c def get_relay_config(self):
from azure.communication.networktraversal.aio import CommunicationRelayClient
from azure.communication.identity.aio import CommunicationIdentityClient

if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
    from azure.identity.aio import DefaultAzureCredential
    endpoint, _ = parse_connection_str(self.connection_string)
    identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
    relay_client = CommunicationRelayClient(endpoint, DefaultAzureCredential())
else:
    identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
    relay_client = CommunicationRelayClient.from_connection_string(self.connection_string)

async with identity_client:
    print("Creating new user")
    user = await identity_client.create_user()
    print("User created with id:" + user.properties.get('id'))

async with relay_client:
    print("Getting relay configuration")
    relay_configuration = await relay_client.get_relay_configuration(user)

for iceServer in relay_configuration.ice_servers:
    print("Icer server:")
    print(iceServer)

f main():
le = CommunicationRelayClientSamples()
t sample.get_relay_config()

e__ == '__main__':
 = asyncio.get_event_loop()
.run_until_complete(main())
async close()None[source]

Close the :class: ~azure.communication.networktraversal.aio.CommunicationRelayClient session.

classmethod from_connection_string(conn_str: str, **kwargs)azure.communication.networktraversal.aio._communication_relay_client_async.CommunicationRelayClient[source]

Create CommunicationRelayClient from a Connection String.

Parameters

conn_str (str) – A connection string to an Azure Communication Service resource.

Returns

Instance of CommunicationRelayClient.

Return type

CommunicationRelayClient

Example:

async get_relay_configuration(user: CommunicationUserIdentifier = None, route_type: CommunicationRelayConfigurationRequestRouteType = None, **kwargs)CommunicationRelayConfiguration[source]

get a Communication Relay configuration. :param user: Azure Communication User :type user: ~azure.communication.identity.CommunicationUserIdentifier :param route_type: Azure Communication Route Type :type route_type: ~azure.communication.networktraversal.RouteType :return: CommunicationRelayConfiguration :rtype: ~azure.communication.networktraversal.models.CommunicationRelayConfiguration

class azure.communication.networktraversal.aio.RouteType(value)[source]

The routing methodology to where the ICE server will be located from the client.

ANY = 'any'
NEAREST = 'nearest'