mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
feat: clean up legacy code and remove excessive documentation
- Remove excessive inline comments from meeting creation flow - Remove verbose docstrings from simple property methods and basic functions - Clean up obvious comments like 'Generate JWT tokens', 'Build room URLs' - Remove unnecessary explanatory comments in platform clients - Keep only essential documentation for complex logic - Simplify race condition handling comments - Remove excessive method documentation for simple operations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,31 +13,23 @@ from ..base import MeetingData, VideoPlatformClient
|
|||||||
|
|
||||||
|
|
||||||
class JitsiMeetingData(MeetingData):
|
class JitsiMeetingData(MeetingData):
|
||||||
"""Jitsi-specific meeting data with typed extra_data."""
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user_jwt(self) -> str:
|
def user_jwt(self) -> str:
|
||||||
"""JWT token for regular users."""
|
|
||||||
return self.extra_data.get("user_jwt", "")
|
return self.extra_data.get("user_jwt", "")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def host_jwt(self) -> str:
|
def host_jwt(self) -> str:
|
||||||
"""JWT token for moderators."""
|
|
||||||
return self.extra_data.get("host_jwt", "")
|
return self.extra_data.get("host_jwt", "")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def domain(self) -> str:
|
def domain(self) -> str:
|
||||||
"""Jitsi domain."""
|
|
||||||
return self.extra_data.get("domain", "")
|
return self.extra_data.get("domain", "")
|
||||||
|
|
||||||
|
|
||||||
class JitsiClient(VideoPlatformClient):
|
class JitsiClient(VideoPlatformClient):
|
||||||
"""Jitsi Meet video platform implementation."""
|
|
||||||
|
|
||||||
PLATFORM_NAME = VideoPlatform.JITSI
|
PLATFORM_NAME = VideoPlatform.JITSI
|
||||||
|
|
||||||
def _generate_jwt(self, room: str, moderator: bool, exp: datetime) -> str:
|
def _generate_jwt(self, room: str, moderator: bool, exp: datetime) -> str:
|
||||||
"""Generate JWT token for Jitsi Meet room access."""
|
|
||||||
if not settings.JITSI_JWT_SECRET:
|
if not settings.JITSI_JWT_SECRET:
|
||||||
raise ValueError("JITSI_JWT_SECRET is required for JWT generation")
|
raise ValueError("JITSI_JWT_SECRET is required for JWT generation")
|
||||||
|
|
||||||
@@ -64,15 +56,11 @@ class JitsiClient(VideoPlatformClient):
|
|||||||
async def create_meeting(
|
async def create_meeting(
|
||||||
self, room_name_prefix: str, end_date: datetime, room: Room
|
self, room_name_prefix: str, end_date: datetime, room: Room
|
||||||
) -> JitsiMeetingData:
|
) -> JitsiMeetingData:
|
||||||
"""Create a Jitsi Meet room with JWT authentication."""
|
|
||||||
# Generate unique room name
|
|
||||||
jitsi_room = f"reflector-{room.name}-{generate_uuid4()}"
|
jitsi_room = f"reflector-{room.name}-{generate_uuid4()}"
|
||||||
|
|
||||||
# Generate JWT tokens
|
|
||||||
user_jwt = self._generate_jwt(room=jitsi_room, moderator=False, exp=end_date)
|
user_jwt = self._generate_jwt(room=jitsi_room, moderator=False, exp=end_date)
|
||||||
host_jwt = self._generate_jwt(room=jitsi_room, moderator=True, exp=end_date)
|
host_jwt = self._generate_jwt(room=jitsi_room, moderator=True, exp=end_date)
|
||||||
|
|
||||||
# Build room URLs with JWT tokens
|
|
||||||
room_url = f"https://{settings.JITSI_DOMAIN}/{jitsi_room}?jwt={user_jwt}"
|
room_url = f"https://{settings.JITSI_DOMAIN}/{jitsi_room}?jwt={user_jwt}"
|
||||||
host_room_url = f"https://{settings.JITSI_DOMAIN}/{jitsi_room}?jwt={host_jwt}"
|
host_room_url = f"https://{settings.JITSI_DOMAIN}/{jitsi_room}?jwt={host_jwt}"
|
||||||
|
|
||||||
@@ -90,7 +78,6 @@ class JitsiClient(VideoPlatformClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def get_room_sessions(self, room_name: str) -> Dict[str, Any]:
|
async def get_room_sessions(self, room_name: str) -> Dict[str, Any]:
|
||||||
"""Get room sessions (mock implementation - Jitsi doesn't provide sessions API)."""
|
|
||||||
return {
|
return {
|
||||||
"roomName": room_name,
|
"roomName": room_name,
|
||||||
"sessions": [
|
"sessions": [
|
||||||
@@ -104,17 +91,14 @@ class JitsiClient(VideoPlatformClient):
|
|||||||
}
|
}
|
||||||
|
|
||||||
async def delete_room(self, room_name: str) -> bool:
|
async def delete_room(self, room_name: str) -> bool:
|
||||||
"""Delete room (no-op - Jitsi rooms auto-expire with JWT expiration)."""
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def upload_logo(self, room_name: str, logo_path: str) -> bool:
|
async def upload_logo(self, room_name: str, logo_path: str) -> bool:
|
||||||
"""Upload logo (no-op - custom branding handled via Jitsi server config)."""
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def verify_webhook_signature(
|
def verify_webhook_signature(
|
||||||
self, body: bytes, signature: str, timestamp: Optional[str] = None
|
self, body: bytes, signature: str, timestamp: Optional[str] = None
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Verify webhook signature for Prosody event-sync webhooks."""
|
|
||||||
if not signature or not self.config.webhook_secret:
|
if not signature or not self.config.webhook_secret:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ from ..base import MeetingData, VideoPlatformClient
|
|||||||
|
|
||||||
|
|
||||||
class WherebyClient(VideoPlatformClient):
|
class WherebyClient(VideoPlatformClient):
|
||||||
"""Whereby video platform implementation."""
|
|
||||||
|
|
||||||
PLATFORM_NAME = VideoPlatform.WHEREBY
|
PLATFORM_NAME = VideoPlatform.WHEREBY
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
@@ -27,7 +25,6 @@ class WherebyClient(VideoPlatformClient):
|
|||||||
async def create_meeting(
|
async def create_meeting(
|
||||||
self, room_name_prefix: str, end_date: datetime, room: Room
|
self, room_name_prefix: str, end_date: datetime, room: Room
|
||||||
) -> MeetingData:
|
) -> MeetingData:
|
||||||
"""Create a Whereby meeting room."""
|
|
||||||
data = {
|
data = {
|
||||||
"isLocked": room.is_locked,
|
"isLocked": room.is_locked,
|
||||||
"roomNamePrefix": room_name_prefix,
|
"roomNamePrefix": room_name_prefix,
|
||||||
@@ -72,7 +69,6 @@ class WherebyClient(VideoPlatformClient):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def get_room_sessions(self, room_name: str) -> Dict[str, Any]:
|
async def get_room_sessions(self, room_name: str) -> Dict[str, Any]:
|
||||||
"""Get session information for a room."""
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
f"{self.config.api_url}/insights/room-sessions?roomName={room_name}",
|
f"{self.config.api_url}/insights/room-sessions?roomName={room_name}",
|
||||||
@@ -83,11 +79,9 @@ class WherebyClient(VideoPlatformClient):
|
|||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
async def delete_room(self, room_name: str) -> bool:
|
async def delete_room(self, room_name: str) -> bool:
|
||||||
"""Delete a room. Whereby rooms auto-expire, so this is a no-op."""
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def upload_logo(self, room_name: str, logo_path: str) -> bool:
|
async def upload_logo(self, room_name: str, logo_path: str) -> bool:
|
||||||
"""Upload a logo to the room."""
|
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
with open(logo_path, "rb") as f:
|
with open(logo_path, "rb") as f:
|
||||||
@@ -107,7 +101,6 @@ class WherebyClient(VideoPlatformClient):
|
|||||||
def verify_webhook_signature(
|
def verify_webhook_signature(
|
||||||
self, body: bytes, signature: str, timestamp: Optional[str] = None
|
self, body: bytes, signature: str, timestamp: Optional[str] = None
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Verify webhook signature for Whereby webhooks."""
|
|
||||||
if not signature or not self.config.webhook_secret:
|
if not signature or not self.config.webhook_secret:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ router = APIRouter()
|
|||||||
|
|
||||||
|
|
||||||
def parse_datetime_with_timezone(iso_string: str) -> datetime:
|
def parse_datetime_with_timezone(iso_string: str) -> datetime:
|
||||||
"""Parse ISO datetime string and ensure timezone awareness (defaults to UTC if naive)."""
|
|
||||||
dt = datetime.fromisoformat(iso_string)
|
dt = datetime.fromisoformat(iso_string)
|
||||||
if dt.tzinfo is None:
|
if dt.tzinfo is None:
|
||||||
dt = dt.replace(tzinfo=timezone.utc)
|
dt = dt.replace(tzinfo=timezone.utc)
|
||||||
@@ -202,11 +201,9 @@ async def rooms_create_meeting(
|
|||||||
if meeting is None:
|
if meeting is None:
|
||||||
end_date = current_time + timedelta(hours=8)
|
end_date = current_time + timedelta(hours=8)
|
||||||
|
|
||||||
# Use platform abstraction to create meeting
|
|
||||||
platform = room.platform
|
platform = room.platform
|
||||||
client = create_platform_client(platform)
|
client = create_platform_client(platform)
|
||||||
|
|
||||||
# Use platform client
|
|
||||||
platform_meeting = await client.create_meeting("", end_date=end_date, room=room)
|
platform_meeting = await client.create_meeting("", end_date=end_date, room=room)
|
||||||
await client.upload_logo(platform_meeting.room_name, "./images/logo.png")
|
await client.upload_logo(platform_meeting.room_name, "./images/logo.png")
|
||||||
|
|
||||||
@@ -215,11 +212,9 @@ async def rooms_create_meeting(
|
|||||||
"room_name": platform_meeting.room_name,
|
"room_name": platform_meeting.room_name,
|
||||||
"room_url": platform_meeting.room_url,
|
"room_url": platform_meeting.room_url,
|
||||||
"host_room_url": platform_meeting.host_room_url,
|
"host_room_url": platform_meeting.host_room_url,
|
||||||
"start_date": current_time, # Platform client provides datetime objects
|
"start_date": current_time,
|
||||||
"end_date": end_date,
|
"end_date": end_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Now try to save to database
|
|
||||||
try:
|
try:
|
||||||
meeting = await meetings_controller.create(
|
meeting = await meetings_controller.create(
|
||||||
id=meeting_data["meeting_id"],
|
id=meeting_data["meeting_id"],
|
||||||
@@ -232,8 +227,6 @@ async def rooms_create_meeting(
|
|||||||
room=room,
|
room=room,
|
||||||
)
|
)
|
||||||
except (asyncpg.exceptions.UniqueViolationError, sqlite3.IntegrityError):
|
except (asyncpg.exceptions.UniqueViolationError, sqlite3.IntegrityError):
|
||||||
# Another request already created a meeting for this room
|
|
||||||
# Log this race condition occurrence
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Race condition detected for room %s - fetching existing meeting",
|
"Race condition detected for room %s - fetching existing meeting",
|
||||||
room.name,
|
room.name,
|
||||||
@@ -243,13 +236,10 @@ async def rooms_create_meeting(
|
|||||||
meeting_data["meeting_id"],
|
meeting_data["meeting_id"],
|
||||||
room.name,
|
room.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Fetch the meeting that was created by the other request
|
|
||||||
meeting = await meetings_controller.get_active(
|
meeting = await meetings_controller.get_active(
|
||||||
room=room, current_time=current_time
|
room=room, current_time=current_time
|
||||||
)
|
)
|
||||||
if meeting is None:
|
if meeting is None:
|
||||||
# Edge case: meeting was created but expired/deleted between checks
|
|
||||||
logger.error(
|
logger.error(
|
||||||
"Meeting disappeared after race condition for room %s", room.name
|
"Meeting disappeared after race condition for room %s", room.name
|
||||||
)
|
)
|
||||||
@@ -268,7 +258,6 @@ async def rooms_test_webhook(
|
|||||||
room_id: str,
|
room_id: str,
|
||||||
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
user: Annotated[Optional[auth.UserInfo], Depends(auth.current_user_optional)],
|
||||||
):
|
):
|
||||||
"""Test webhook configuration by sending a sample payload."""
|
|
||||||
user_id = user["sub"] if user else None
|
user_id = user["sub"] if user else None
|
||||||
|
|
||||||
room = await rooms_controller.get_by_id(room_id)
|
room = await rooms_controller.get_by_id(room_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user