From 54ededca6c80eff058aa083608c8016476826dd9 Mon Sep 17 00:00:00 2001 From: Jay-fly Date: Mon, 25 Aug 2025 10:47:55 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=88=BF=E9=96=93=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A6=96=E9=A0=BB=E5=93=81=E8=B3=AA=E9=81=B8?= =?UTF-8?q?=E6=93=87=E5=8F=8A=E7=B5=B1=E8=A8=88=E9=A1=AF=E7=A4=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在房間控制介面中新增視頻品質選擇下拉選單,使用者可選擇自動、高、中、低品質。 - 新增視頻統計顯示,顯示解析度、位元率及幀率等資訊。 - 強制設定視頻品質為最高,並在參與者連接時自動應用。 - 改善使用者介面,增強房間管理功能的可用性。 - 更新文檔以反映新增的功能和指令。 --- CLAUDE.md | 52 +++++++- main.py | 10 +- static/index.html | 319 ++++++++++++++++++++++++++++++++++++++++++++- static/index2.html | 1 + 4 files changed, 367 insertions(+), 15 deletions(-) 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 @@

尚未添加任何房間