mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
feat: add typing overloads and clean up platform client factory
- Add typing overloads to get_platform_client for JitsiClient and WherebyClient return types - Add overloads to create_platform_client in factory for better IDE support - Remove PyJWT fallback imports from views/rooms.py - Remove platform defaults from CreateRoom and UpdateRoom models - Clean up legacy whereby fallback code in meeting creation - Use direct platform client access instead of conditional fallbacks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"""Factory for creating video platform clients based on configuration."""
|
"""Factory for creating video platform clients based on configuration."""
|
||||||
|
|
||||||
from typing import Optional
|
from typing import TYPE_CHECKING, Literal, Optional, overload
|
||||||
|
|
||||||
from reflector.db.rooms import VideoPlatform
|
from reflector.db.rooms import VideoPlatform
|
||||||
from reflector.settings import settings
|
from reflector.settings import settings
|
||||||
@@ -8,6 +8,10 @@ from reflector.settings import settings
|
|||||||
from .base import VideoPlatformClient, VideoPlatformConfig
|
from .base import VideoPlatformClient, VideoPlatformConfig
|
||||||
from .registry import get_platform_client
|
from .registry import get_platform_client
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .jitsi import JitsiClient
|
||||||
|
from .whereby import WherebyClient
|
||||||
|
|
||||||
|
|
||||||
def get_platform_config(platform: str) -> VideoPlatformConfig:
|
def get_platform_config(platform: str) -> VideoPlatformConfig:
|
||||||
"""Get configuration for a specific platform."""
|
"""Get configuration for a specific platform."""
|
||||||
@@ -30,6 +34,14 @@ def get_platform_config(platform: str) -> VideoPlatformConfig:
|
|||||||
raise ValueError(f"Unknown platform: {platform}")
|
raise ValueError(f"Unknown platform: {platform}")
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def create_platform_client(platform: Literal["jitsi"]) -> "JitsiClient": ...
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def create_platform_client(platform: Literal["whereby"]) -> "WherebyClient": ...
|
||||||
|
|
||||||
|
|
||||||
def create_platform_client(platform: str) -> VideoPlatformClient:
|
def create_platform_client(platform: str) -> VideoPlatformClient:
|
||||||
"""Create a video platform client instance."""
|
"""Create a video platform client instance."""
|
||||||
config = get_platform_config(platform)
|
config = get_platform_config(platform)
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
from typing import Dict, Type
|
from typing import TYPE_CHECKING, Dict, Literal, Type, overload
|
||||||
|
|
||||||
from .base import VideoPlatformClient, VideoPlatformConfig
|
from .base import VideoPlatformClient, VideoPlatformConfig
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .jitsi import JitsiClient
|
||||||
|
from .whereby import WherebyClient
|
||||||
|
|
||||||
# Registry of available video platforms
|
# Registry of available video platforms
|
||||||
_PLATFORMS: Dict[str, Type[VideoPlatformClient]] = {}
|
_PLATFORMS: Dict[str, Type[VideoPlatformClient]] = {}
|
||||||
|
|
||||||
@@ -11,6 +15,18 @@ def register_platform(name: str, client_class: Type[VideoPlatformClient]):
|
|||||||
_PLATFORMS[name.lower()] = client_class
|
_PLATFORMS[name.lower()] = client_class
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def get_platform_client(
|
||||||
|
platform: Literal["jitsi"], config: VideoPlatformConfig
|
||||||
|
) -> "JitsiClient": ...
|
||||||
|
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def get_platform_client(
|
||||||
|
platform: Literal["whereby"], config: VideoPlatformConfig
|
||||||
|
) -> "WherebyClient": ...
|
||||||
|
|
||||||
|
|
||||||
def get_platform_client(
|
def get_platform_client(
|
||||||
platform: str, config: VideoPlatformConfig
|
platform: str, config: VideoPlatformConfig
|
||||||
) -> VideoPlatformClient:
|
) -> VideoPlatformClient:
|
||||||
|
|||||||
@@ -14,21 +14,10 @@ from reflector.db import get_database
|
|||||||
from reflector.db.meetings import meetings_controller
|
from reflector.db.meetings import meetings_controller
|
||||||
from reflector.db.rooms import VideoPlatform, rooms_controller
|
from reflector.db.rooms import VideoPlatform, rooms_controller
|
||||||
from reflector.settings import settings
|
from reflector.settings import settings
|
||||||
from reflector.worker.webhook import test_webhook
|
from reflector.video_platforms.factory import (
|
||||||
|
|
||||||
try:
|
|
||||||
from reflector.video_platforms.factory import (
|
|
||||||
create_platform_client,
|
create_platform_client,
|
||||||
get_platform_for_room,
|
)
|
||||||
)
|
from reflector.worker.webhook import test_webhook
|
||||||
except ImportError:
|
|
||||||
# Fallback for when PyJWT not yet installed
|
|
||||||
def create_platform_client(platform: str):
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_platform_for_room(room_id: str = None) -> str:
|
|
||||||
return "whereby"
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -86,7 +75,7 @@ class CreateRoom(BaseModel):
|
|||||||
is_shared: bool
|
is_shared: bool
|
||||||
webhook_url: str
|
webhook_url: str
|
||||||
webhook_secret: str
|
webhook_secret: str
|
||||||
platform: VideoPlatform = VideoPlatform.WHEREBY
|
platform: VideoPlatform
|
||||||
|
|
||||||
|
|
||||||
class UpdateRoom(BaseModel):
|
class UpdateRoom(BaseModel):
|
||||||
@@ -101,7 +90,7 @@ class UpdateRoom(BaseModel):
|
|||||||
is_shared: bool
|
is_shared: bool
|
||||||
webhook_url: str
|
webhook_url: str
|
||||||
webhook_secret: str
|
webhook_secret: str
|
||||||
platform: VideoPlatform = VideoPlatform.WHEREBY
|
platform: VideoPlatform
|
||||||
|
|
||||||
|
|
||||||
class DeletionStatus(BaseModel):
|
class DeletionStatus(BaseModel):
|
||||||
@@ -214,36 +203,11 @@ async def rooms_create_meeting(
|
|||||||
end_date = current_time + timedelta(hours=8)
|
end_date = current_time + timedelta(hours=8)
|
||||||
|
|
||||||
# Use platform abstraction to create meeting
|
# Use platform abstraction to create meeting
|
||||||
platform = getattr(
|
platform = room.platform
|
||||||
room, "platform", "whereby"
|
|
||||||
) # Default to whereby for existing rooms
|
|
||||||
client = create_platform_client(platform)
|
client = create_platform_client(platform)
|
||||||
|
|
||||||
# Fallback to legacy whereby implementation if client not available
|
|
||||||
if client is None:
|
|
||||||
from reflector.whereby import create_meeting as whereby_create_meeting
|
|
||||||
from reflector.whereby import upload_logo as whereby_upload_logo
|
|
||||||
|
|
||||||
whereby_meeting = await whereby_create_meeting(
|
|
||||||
"", end_date=end_date, room=room
|
|
||||||
)
|
|
||||||
await whereby_upload_logo(whereby_meeting["roomName"], "./images/logo.png")
|
|
||||||
|
|
||||||
meeting_data = {
|
|
||||||
"meeting_id": whereby_meeting["meetingId"],
|
|
||||||
"room_name": whereby_meeting["roomName"],
|
|
||||||
"room_url": whereby_meeting["roomUrl"],
|
|
||||||
"host_room_url": whereby_meeting["hostRoomUrl"],
|
|
||||||
"start_date": parse_datetime_with_timezone(
|
|
||||||
whereby_meeting["startDate"]
|
|
||||||
),
|
|
||||||
"end_date": parse_datetime_with_timezone(whereby_meeting["endDate"]),
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
# Use platform client
|
# Use platform client
|
||||||
platform_meeting = await client.create_meeting(
|
platform_meeting = await client.create_meeting("", end_date=end_date, room=room)
|
||||||
"", 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")
|
||||||
|
|
||||||
meeting_data = {
|
meeting_data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user