async 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)
async def test_get_relay_configuration_with_route_type_nearest( self, communication_livetest_dynamic_connection_string): identity_client = CommunicationIdentityClient.from_connection_string( communication_livetest_dynamic_connection_string, http_logging_policy=get_http_logging_policy()) async with identity_client: user = await identity_client.create_user() networkTraversalClient = CommunicationRelayClient.from_connection_string( communication_livetest_dynamic_connection_string, http_logging_policy=get_http_logging_policy()) async with networkTraversalClient: print('Getting relay config with nearest type:\n') config = await networkTraversalClient.get_relay_configuration( user=user, route_type=RouteType.NEAREST) print('Ice Servers Async:\n') for iceServer in config.ice_servers: assert iceServer.username is not None print('Username: '******'Credential: ' + iceServer.credential) assert iceServer.urls is not None for url in iceServer.urls: print('Url:' + url) assert iceServer.route_type == RouteType.NEAREST assert config is not None
async def test_get_relay_configuration( self, communication_livetest_dynamic_connection_string): identity_client = CommunicationIdentityClient.from_connection_string( communication_livetest_dynamic_connection_string, api_version=ApiVersion.V2021_03_07, http_logging_policy=get_http_logging_policy()) async with identity_client: user = await identity_client.create_user() networkTraversalClient = CommunicationRelayClient.from_connection_string( communication_livetest_dynamic_connection_string, http_logging_policy=get_http_logging_policy()) async with networkTraversalClient: print('Getting relay config:\n') config = await networkTraversalClient.get_relay_configuration(user) print('Ice Servers Async:\n') for iceServer in config.ice_servers: assert iceServer.username is not None print('Username: '******'Credential: ' + iceServer.credential) assert iceServer.urls is not None for url in iceServer.urls: print('Url:' + url) assert config is not None
async def get_relay_config_no_identity(self): from azure.communication.networktraversal.aio import CommunicationRelayClient 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) relay_client = CommunicationRelayClient(endpoint, DefaultAzureCredential()) else: relay_client = CommunicationRelayClient.from_connection_string( self.connection_string) async with relay_client: print("Getting relay configuration") relay_configuration = await relay_client.get_relay_configuration() for iceServer in relay_configuration.ice_servers: print("Icer server:") print(iceServer)
async def test_get_relay_configuration_with_ttl( self, communication_livetest_dynamic_connection_string): networkTraversalClient = CommunicationRelayClient.from_connection_string( communication_livetest_dynamic_connection_string, http_logging_policy=get_http_logging_policy()) expiry_time = 100 # Make the request time to be time zome aware request_time = datetime.now() + timedelta(seconds=expiry_time) request_time = request_time.replace(tzinfo=timezone.utc) async with networkTraversalClient: print('Getting relay config with nearest type:\n') config = await networkTraversalClient.get_relay_configuration( ttl=expiry_time) assert config is not None print('Requested time:' + request_time.strftime("%m/%d/%Y, %H:%M:%S")) print('Expires on:' + config.expires_on.strftime("%m/%d/%Y, %H:%M:%S")) if self.is_live: assert request_time <= config.expires_on print('Ice Servers Async:\n') for iceServer in config.ice_servers: assert iceServer.username is not None print('Username: '******'Credential: ' + iceServer.credential) assert iceServer.urls is not None for url in iceServer.urls: print('Url:' + url) print(iceServer.route_type) assert iceServer.route_type is not None
async def test_get_relay_configuration_without_identity( self, communication_livetest_dynamic_connection_string): networkTraversalClient = CommunicationRelayClient.from_connection_string( communication_livetest_dynamic_connection_string, http_logging_policy=get_http_logging_policy()) async with networkTraversalClient: print('Getting relay config:\n') config = await networkTraversalClient.get_relay_configuration() print('Ice Servers Async:\n') for iceServer in config.ice_servers: assert iceServer.username is not None print('Username: '******'Credential: ' + iceServer.credential) assert iceServer.urls is not None for url in iceServer.urls: print('Url:' + url) assert config is not None