diff --git a/CLAUDE.md b/CLAUDE.md index 5a7fdec..ab1df7d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1 +1,51 @@ -這個專案的套件管理是使用 PDM,所以有關套件的安裝是使用 `pdm install ...`,不要直接更改 pyproject.toml \ No newline at end of file +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Package Management +這個專案的套件管理是使用 PDM,所以有關套件的安裝是使用 `pdm install ...`,不要直接更改 pyproject.toml + +## Common Commands +- `pdm install` - Install all dependencies +- `pdm add ` - Add new dependency +- `python main.py` - Run the FastAPI server locally (default port 8000) +- `uvicorn main:app --host 0.0.0.0 --port 8000` - Alternative way to run the server +- `python create_ingress.py` - Create a new LiveKit ingress endpoint +- `python info.py` - Check ingress status and information +- `python delete.py` - List and delete ingress endpoints + +## Project Architecture +This is a LiveKit-based real-time communication (RTC) application with the following structure: + +### Core Components +1. **FastAPI Server** (`main.py`) - Main web application serving: + - `/` - Viewer frontend (static/index.html) + - `/mobile` - Mobile publisher frontend (static/index2.html) + - `/api/token` - Generate viewer tokens for LiveKit rooms + - `/api/publisher-token` - Generate publisher tokens for mobile streaming + +2. **LiveKit Management Scripts**: + - `create_ingress.py` - Creates WHIP ingress endpoints for streaming + - `info.py` - Lists and monitors ingress status + - `delete.py` - Manages ingress cleanup + +3. **Frontend** (`static/`): + - `index.html` - Viewer interface with room management + - `index2.html` - Mobile publisher interface + - Service worker and manifest for PWA functionality + +### Key Configuration +- Uses `.env` file for LiveKit credentials (API_KEY, API_SECRET, SERVER_URL) +- Default room name: "Drone-RTC-01" +- Supports both viewer and publisher token generation +- CORS enabled for cross-origin requests + +### Dependencies +- `livekit` - Core LiveKit SDK +- `livekit-api` - LiveKit API client +- `fastapi` - Web framework +- `uvicorn` - ASGI server +- Audio processing: `faster-whisper`, `resampy`, `numpy`, `scipy`, `numba` +- Environment: `python-dotenv` + +The application follows a microservice pattern with separate scripts for different LiveKit operations, centered around a FastAPI web server that provides both frontend interfaces and API endpoints for token generation. \ No newline at end of file diff --git a/main.py b/main.py index e187cd3..6220772 100644 --- a/main.py +++ b/main.py @@ -75,17 +75,11 @@ async def get_publisher_token(room: str = "Drone-RTC-01", identity: str = None) # 如果沒有提供身份,自動生成一個 if not identity: identity = f"mobile-publisher-{secrets.token_hex(4)}" - + at = ( api.AccessToken(API_KEY, API_SECRET) .with_identity(identity) - .with_grants(api.VideoGrants( - room=room, - room_join=True, - can_subscribe=True, - can_publish=True, - can_publish_data=True - )) + .with_grants(api.VideoGrants(room=room, room_join=True, can_subscribe=True, can_publish=True, can_publish_data=True)) ) return {"identity": identity, "token": at.to_jwt(), "server_url": SERVER_URL, "room": room} except Exception as e: diff --git a/static/index.html b/static/index.html index 3889934..708519f 100644 --- a/static/index.html +++ b/static/index.html @@ -58,7 +58,7 @@ min-width: 200px; } - input, button { + input, button, select { padding: 10px 16px; font-size: 14px; border-radius: 8px; @@ -78,6 +78,24 @@ box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); } + select { + background: var(--bg-primary); + color: var(--text-primary); + cursor: pointer; + min-width: 100px; + } + + select:focus { + outline: none; + border-color: var(--primary-color); + box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); + } + + .quality-select { + font-size: 12px; + padding: 8px 12px; + } + button { background: var(--primary-color); color: white; @@ -107,6 +125,16 @@ background: #dc2626; } + button.secondary { + background: var(--secondary-color); + padding: 8px 12px; + font-size: 12px; + } + + button.secondary:hover { + background: #4a5568; + } + .rooms-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); @@ -247,7 +275,7 @@

尚未添加任何房間