97 lines
3.6 KiB
Python
97 lines
3.6 KiB
Python
"""
|
||
Скрипт для тестирования создания видеокомнаты через Django API.
|
||
Использование: python manage.py shell < test_video_room.py
|
||
"""
|
||
|
||
from apps.schedule.models import Lesson
|
||
from apps.users.models import User, Client
|
||
from apps.video.models import VideoRoom
|
||
from apps.video.services import get_sfu_client
|
||
from django.utils import timezone
|
||
from datetime import timedelta
|
||
import uuid
|
||
|
||
# Получаем пользователей
|
||
mentor = User.objects.filter(role='mentor').first()
|
||
client_user = User.objects.filter(role='client').first()
|
||
|
||
if not mentor or not client_user:
|
||
print("❌ Не найдены пользователи (mentor или client)")
|
||
exit(1)
|
||
|
||
client_obj = Client.objects.filter(user=client_user).first()
|
||
if not client_obj:
|
||
print("❌ Не найден объект Client")
|
||
exit(1)
|
||
|
||
print(f"✅ Mentor: {mentor.email}")
|
||
print(f"✅ Client: {client_obj.user.email}")
|
||
|
||
# Ищем или создаем занятие
|
||
lesson = Lesson.objects.filter(
|
||
mentor=mentor,
|
||
client=client_obj,
|
||
status__in=['scheduled', 'in_progress']
|
||
).first()
|
||
|
||
if not lesson:
|
||
# Создаем тестовое занятие
|
||
start_time = timezone.now() + timedelta(hours=1)
|
||
lesson = Lesson.objects.create(
|
||
mentor=mentor,
|
||
client=client_obj,
|
||
title='Тестовое занятие для видеоконференции',
|
||
start_time=start_time,
|
||
end_time=start_time + timedelta(minutes=60),
|
||
duration=60,
|
||
status='scheduled'
|
||
)
|
||
print(f"✅ Создано тестовое занятие: {lesson.id}")
|
||
else:
|
||
print(f"✅ Найдено занятие: {lesson.id}")
|
||
|
||
# Проверяем, есть ли уже видеокомната
|
||
if hasattr(lesson, 'video_room'):
|
||
print(f"⚠️ Видеокомната уже существует: {lesson.video_room.room_id}")
|
||
video_room = lesson.video_room
|
||
else:
|
||
# Создаем видеокомнату
|
||
video_room = VideoRoom.objects.create(
|
||
lesson=lesson,
|
||
mentor=mentor,
|
||
client=client_obj.user,
|
||
is_recording=False,
|
||
max_participants=2
|
||
)
|
||
print(f"✅ Создана видеокомната: {video_room.room_id}")
|
||
|
||
# Проверяем создание в sfu-server
|
||
sfu_client = get_sfu_client()
|
||
try:
|
||
if sfu_client.health_check():
|
||
print("✅ SFU server доступен")
|
||
|
||
# Проверяем, существует ли комната в sfu-server
|
||
try:
|
||
room_info = sfu_client.get_room(str(video_room.room_id))
|
||
print(f"✅ Комната существует в sfu-server: {room_info}")
|
||
except Exception as e:
|
||
print(f"⚠️ Комната не найдена в sfu-server, создаем...")
|
||
result = sfu_client.create_room(str(video_room.room_id))
|
||
print(f"✅ Комната создана в sfu-server: {result}")
|
||
else:
|
||
print("❌ SFU server недоступен")
|
||
except Exception as e:
|
||
print(f"❌ Ошибка проверки SFU server: {e}")
|
||
|
||
print(f"\n📋 Информация о видеокомнате:")
|
||
print(f" Room ID: {video_room.room_id}")
|
||
print(f" Lesson: {lesson.title}")
|
||
print(f" Mentor: {mentor.email}")
|
||
print(f" Client: {client_obj.user.email}")
|
||
print(f" Status: {video_room.status}")
|
||
print(f"\n🔗 URL для подключения:")
|
||
print(f" Frontend: http://localhost:3000/video/room/{video_room.room_id}")
|
||
print(f" WebSocket: ws://localhost:7001/ws/{video_room.room_id}")
|
||
|