Azure Communication Network Traversal Package-klientbibliotek för Python – version 1.0.0
Azure Communication Network Traversal hanterar TURN-autentiseringsuppgifter för Azure Communication Services.
Den tillhandahåller TURN-autentiseringsuppgifter till en användare.
Källkod | API-referensdokumentation
Friskrivning
Stöd för Azure SDK Python-paket för Python 2.7 har upphört den 1 januari 2022. Mer information och frågor finns i https://github.com/Azure/azure-sdk-for-python/issues/20691
Komma igång
Förutsättningar
- Python 3.6 eller senare krävs för att använda det här paketet.
- Du måste ha en Azure-prenumeration
- En distribuerad Communication Services-resurs. Du kan använda Azure-portalen eller Azure PowerShell för att konfigurera den.
Installera paketet
Installera Azure Communication Identity-klientbiblioteket för Python med pip: Installera Azure Communication Relay-klientbiblioteket för Python med pip:
pip install azure-communication-identity
pip install azure-communication-networktraversal
Viktiga begrepp
Exempel
Initierar Relay-klienten
I följande avsnitt finns kodfragment som omfattar några av de vanligaste bläddningsuppgifterna för Azure Communication Network, inklusive:
# You can find your endpoint and access token from your resource in the Azure Portal
import os
from azure.communication.networktraversal import CommunicationRelayClient
from azure.identity import DefaultAzureCredential
from azure.communication.identity import CommunicationIdentityClient
connection_str = "endpoint=ENDPOINT;accessKey=KEY"
endpoint = "https://<RESOURCE_NAME>.communication.azure.com"
# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have
# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.
# We also need Identity client to get a User Identifier
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
relay_client = CommunicationRelayClient(endpoint, DefaultAzureCredential())
#You kan också autentisera med hjälp av anslutningssträngen
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
relay_client = CommunicationRelayClient.from_connection_string(self.connection_string)
Hämta reläkonfigurationen som ger en användare
# We need a user from Identity
user = identity_client.create_user()
relay_configuration = relay_client.get_relay_configuration(user=user)
for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)
assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)
assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
Hämta reläkonfigurationen utan att tillhandahålla en användare
relay_configuration = relay_client.get_relay_configuration()
for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)
assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)
assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
Hämta reläkonfigurationen utan att ange en RouteType
# We need a user from Identity
user = identity_client.create_user()
relay_configuration = relay_client.get_relay_configuration(user=user, route_type=RouteType.NEAREST)
for iceServer in config.ice_servers:
assert iceServer.username is not None
print('Username: ' + iceServer.username)
assert iceServer.credential is not None
print('Credential: ' + iceServer.credential)
assert iceServer.urls is not None
for url in iceServer.urls:
print('Url:' + url)
Felsökning
Azure Communication Relay-klienten genererar undantag som definierats i Azure Core.
Nästa steg
Mer exempelkod
Ge feedback
Om du stöter på buggar eller har förslag kan du ange ett problem i avsnittet Problem i projektet
Bidra
Det här projektet välkomnar bidrag och förslag. Merparten av bidragen kräver att du godkänner ett licensavtal för bidrag, där du deklarerar att du har behörighet att bevilja oss rättigheten att använda ditt bidrag, och att du dessutom uttryckligen gör så. Mer information finns på https://cla.microsoft.com.
När du skickar en pull-förfrågan avgör en CLA-robot automatiskt om du måste tillhandahålla ett licensavtal för bidrag med lämplig PR (t.ex. etikett eller kommentar). Följ bara robotens anvisningar. Du behöver bara göra detta en gång för alla repor som använder vårt licensavtal för bidrag.
Det här projektet använder sig av Microsofts uppförandekod för öppen källkod. Mer information finns i Vanliga frågor och svar om uppförandekod eller kontakt opencode@microsoft.com med ytterligare frågor eller kommentarer.
Azure SDK for Python
Feedback
https://aka.ms/ContentUserFeedback.
Kommer snart: Under hela 2024 kommer vi att fasa ut GitHub-problem som feedbackmekanism för innehåll och ersätta det med ett nytt feedbacksystem. Mer information finns i:Skicka och visa feedback för