跳转到主要内容

Microsoft Azure Communication Network Traversal Service Client Library for Python

项目描述

Azure Communication Network Traversal Package客户端库

请注意,此包已被弃用,并将在2024年3月31日之后不再维护。

Azure Communication Network Traversal负责管理Azure Communication Services的TURN凭据。

它将为用户提供TURN凭据。

源代码 | API参考文档

免责声明

Azure SDK Python包对Python 2.7的支持已于2022年1月1日结束。有关更多信息,请参阅 https://github.com/Azure/azure-sdk-for-python/issues/20691

入门

请注意,此包已被弃用,并将在2024年3月31日之后不再维护。

关键概念

示例

初始化中继客户端

以下部分提供了代码片段,涵盖了 Azure 通信网络遍历的一些常见任务,包括

# 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())

您也可以使用连接字符串进行认证

identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
relay_client = CommunicationRelayClient.from_connection_string(self.connection_string)

通过用户获取中继配置

# 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)

不提供用户获取中继配置

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)

不提供 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)

故障排除

Azure 通信中继客户端将抛出在 Azure Core 中定义的异常。

下一步

更多示例代码

提供反馈

如果您遇到任何错误或有建议,请在项目的 问题 部分提交问题。

贡献

本项目欢迎贡献和建议。大多数贡献需要您同意贡献者许可协议 (CLA),声明您有权并且实际上确实授予我们使用您的贡献的权利。有关详细信息,请访问 https://cla.microsoft.com

提交拉取请求时,CLA-bot 将自动判断您是否需要提供 CLA,并相应地装饰 PR(例如,标签、注释)。只需按照机器人提供的说明操作。您只需在整个使用我们的 CLA 的所有仓库中这样做一次。

本项目已采用 Microsoft 开源行为准则。有关更多信息,请参阅 行为准则常见问题解答 或通过 opencode@microsoft.com 联系我们,提出任何额外的问题或评论。

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面