feat(voice): add WebRTC voice channels with Cloudflare TURN support

Add voice channel functionality with WebRTC peer-to-peer audio:
- Add VoiceSignalingConsumer for WebRTC signaling and peer coordination
- Add GlobalConsumer for real-time presence and voice status updates
- Add voice channel type to Channel model with current_voice_channel tracking on UserProfile
- Add voice controls UI (mute, deafen, disconnect) in status panel
- Add voice member list display in sidebar with avatar support
- Add
This commit is contained in:
2026-05-23 20:56:37 +02:00
parent 963441fe50
commit 88bdfc797b
14 changed files with 773 additions and 11 deletions
+39
View File
@@ -221,3 +221,42 @@ def handler404(request, exception):
def handler500(request):
return render(request, 'chat/500.html', status=500)
import urllib.request
import urllib.error
import json
from django.conf import settings
@login_required
def voice_credentials_view(request):
account_id = getattr(settings, 'CLOUDFLARE_ACCOUNT_ID', '')
api_token = getattr(settings, 'CLOUDFLARE_API_TOKEN', '')
turn_key_id = getattr(settings, 'CLOUDFLARE_TURN_KEY_ID', '')
if not all([account_id, api_token, turn_key_id]):
return JsonResponse({
"iceServers": [
{"urls": ["stun:stun.cloudflare.com:3478", "stun:stun.cloudflare.com:53"]}
]
})
url = f"https://rtc.live.cloudflare.com/v1/turn/keys/{turn_key_id}/credentials/generate-ice-servers"
headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json"
}
body = json.dumps({"ttl": 86400}).encode("utf-8")
req = urllib.request.Request(url, data=body, headers=headers, method="POST")
try:
with urllib.request.urlopen(req, timeout=5) as response:
res_data = json.loads(response.read().decode())
return JsonResponse(res_data)
except urllib.error.URLError as e:
return JsonResponse({
"error": str(e),
"iceServers": [
{"urls": ["stun:stun.cloudflare.com:3478", "stun:stun.cloudflare.com:53"]}
]
})