|
|
|
@ -180,9 +180,10 @@ class PlugNMeetWebhookAPIView(APIView): |
|
|
|
|
|
|
|
def _handle_room_finished(self, payload: Dict[str, Any]) -> Dict[str, Any]: |
|
|
|
room_data = payload.get('room', {}) |
|
|
|
room_id = room_data.get('identity') |
|
|
|
room_id = room_data.get('room_id') or room_data.get('roomId') or room_data.get('identity') |
|
|
|
|
|
|
|
if not room_id: |
|
|
|
logger.warning(f"⚠️ [PlugNMeet Webhook] Missing room_id in room_finished event. Payload: {payload}") |
|
|
|
return {'message': 'Missing room identity'} |
|
|
|
|
|
|
|
try: |
|
|
|
@ -201,18 +202,27 @@ class PlugNMeetWebhookAPIView(APIView): |
|
|
|
logger.info(f"🏁 [PlugNMeet Webhook] Session {session.id} ended. Users disconnected: {updated_count}") |
|
|
|
return {'session_id': session.id, 'closed_users': updated_count} |
|
|
|
except CourseLiveSession.DoesNotExist: |
|
|
|
logger.warning(f"⚠️ [PlugNMeet Webhook] room_finished: No active session found for room_id {room_id}") |
|
|
|
return {'message': 'No active session found for this room'} |
|
|
|
except Exception as e: |
|
|
|
logger.error(f"❌ [PlugNMeet Webhook] Error in room_finished for room_id {room_id}: {e}", exc_info=True) |
|
|
|
return {'error': str(e)} |
|
|
|
|
|
|
|
def _handle_participant_joined(self, payload: Dict[str, Any]) -> Dict[str, Any]: |
|
|
|
room_data = payload.get('room', {}) |
|
|
|
participant_data = payload.get('participant', {}) |
|
|
|
room_id = room_data.get('identity') |
|
|
|
user_id = participant_data.get('identity') |
|
|
|
room_id = room_data.get('room_id') or room_data.get('roomId') or room_data.get('identity') |
|
|
|
user_id = participant_data.get('identity') or participant_data.get('user_id') or participant_data.get('userId') |
|
|
|
|
|
|
|
if not room_id or not user_id: |
|
|
|
logger.warning(f"⚠️ [PlugNMeet Webhook] Missing room_id or user_id in participant_joined. room_id: {room_id}, user_id: {user_id}. Payload: {payload}") |
|
|
|
return {'message': 'Missing required metadata'} |
|
|
|
|
|
|
|
try: |
|
|
|
if not str(user_id).isdigit(): |
|
|
|
logger.info(f"ℹ️ [PlugNMeet Webhook] Ignoring non-integer user join: {user_id}") |
|
|
|
return {'message': f'Ignored non-integer user_id {user_id}'} |
|
|
|
|
|
|
|
session = CourseLiveSession.objects.get(room_id=room_id, ended_at__isnull=True) |
|
|
|
user = User.objects.get(id=int(user_id)) |
|
|
|
|
|
|
|
@ -228,18 +238,27 @@ class PlugNMeetWebhookAPIView(APIView): |
|
|
|
'entered_at': timezone.now() |
|
|
|
} |
|
|
|
) |
|
|
|
logger.info(f"👤 [PlugNMeet Webhook] User {user.id} joined session {session.id}") |
|
|
|
logger.info(f"👤 [PlugNMeet Webhook] User {user.id} joined session {session.id} (created: {created})") |
|
|
|
return {'session_user_id': session_user.id, 'created': created} |
|
|
|
except Exception as e: |
|
|
|
logger.error(f"❌ [PlugNMeet Webhook] Error in participant_joined (room_id: {room_id}, user_id: {user_id}): {e}", exc_info=True) |
|
|
|
return {'error': str(e)} |
|
|
|
|
|
|
|
def _handle_participant_left(self, payload: Dict[str, Any]) -> Dict[str, Any]: |
|
|
|
room_data = payload.get('room', {}) |
|
|
|
participant_data = payload.get('participant', {}) |
|
|
|
room_id = room_data.get('identity') |
|
|
|
user_id = participant_data.get('identity') |
|
|
|
room_id = room_data.get('room_id') or room_data.get('roomId') or room_data.get('identity') |
|
|
|
user_id = participant_data.get('identity') or participant_data.get('user_id') or participant_data.get('userId') |
|
|
|
|
|
|
|
if not room_id or not user_id: |
|
|
|
logger.warning(f"⚠️ [PlugNMeet Webhook] Missing room_id or user_id in participant_left. room_id: {room_id}, user_id: {user_id}. Payload: {payload}") |
|
|
|
return {'message': 'Missing required metadata'} |
|
|
|
|
|
|
|
try: |
|
|
|
if not str(user_id).isdigit(): |
|
|
|
logger.info(f"ℹ️ [PlugNMeet Webhook] Ignoring non-integer user leave: {user_id}") |
|
|
|
return {'message': f'Ignored non-integer user_id {user_id}'} |
|
|
|
|
|
|
|
session = CourseLiveSession.objects.get(room_id=room_id) |
|
|
|
user = User.objects.get(id=int(user_id)) |
|
|
|
|
|
|
|
@ -247,9 +266,10 @@ class PlugNMeetWebhookAPIView(APIView): |
|
|
|
session=session, user=user, is_online=True |
|
|
|
).update(is_online=False, exited_at=timezone.now(), updated_at=timezone.now()) |
|
|
|
|
|
|
|
logger.info(f"🚪 [PlugNMeet Webhook] User {user.id} left session {session.id}") |
|
|
|
logger.info(f"🚪 [PlugNMeet Webhook] User {user.id} left session {session.id} (updated entries count: {updated})") |
|
|
|
return {'updated': bool(updated)} |
|
|
|
except Exception as e: |
|
|
|
logger.error(f"❌ [PlugNMeet Webhook] Error in participant_left (room_id: {room_id}, user_id: {user_id}): {e}", exc_info=True) |
|
|
|
return {'error': str(e)} |
|
|
|
|
|
|
|
def _get_video_duration(self, video_path: str) -> timezone.timedelta: |
|
|
|
|