Simplify Cloudflare config with new endpoint (#135)

Old instructions will still work, but we now have an endpoint that matches the `RTCPeerConnection` signature exactly.
This commit is contained in:
Michael Hart
2025-03-07 11:25:14 +11:00
committed by GitHub
parent f59e8c3a49
commit 7dfee78261

View File

@@ -100,7 +100,7 @@ turn_key_api_token = os.environ.get("TURN_KEY_API_TOKEN")
ttl = 86400 # Can modify TTL, here it's set to 24 hours ttl = 86400 # Can modify TTL, here it's set to 24 hours
response = requests.post( response = requests.post(
f"https://rtc.live.cloudflare.com/v1/turn/keys/{turn_key_id}/credentials/generate", f"https://rtc.live.cloudflare.com/v1/turn/keys/{turn_key_id}/credentials/generate-ice-servers",
headers={ headers={
"Authorization": f"Bearer {turn_key_api_token}", "Authorization": f"Bearer {turn_key_api_token}",
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -108,14 +108,12 @@ response = requests.post(
json={"ttl": ttl}, json={"ttl": ttl},
) )
if response.ok: if response.ok:
ice_servers = [response.json()["iceServers"]] rtc_configuration = response.json()
else: else:
raise Exception( raise Exception(
f"Failed to get TURN credentials: {response.status_code} {response.text}" f"Failed to get TURN credentials: {response.status_code} {response.text}"
) )
rtc_configuration = {"iceServers": ice_servers}
stream = Stream( stream = Stream(
handler=..., handler=...,
rtc_configuration=rtc_configuration, rtc_configuration=rtc_configuration,