Put web client together
This commit is contained in:
20
app/main.py
20
app/main.py
@@ -4,10 +4,11 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
from pathlib import Path
|
||||||
from typing import Dict, Any, Optional, List
|
from typing import Dict, Any, Optional, List
|
||||||
from fastapi import FastAPI, WebSocket, WebSocketDisconnect, HTTPException
|
from fastapi import FastAPI, WebSocket, WebSocketDisconnect, HTTPException
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse, FileResponse
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
# Try to import aiortc (optional for WebRTC functionality)
|
# Try to import aiortc (optional for WebRTC functionality)
|
||||||
@@ -64,6 +65,7 @@ async def heartbeat_and_timeout_task(
|
|||||||
|
|
||||||
# Initialize FastAPI
|
# Initialize FastAPI
|
||||||
app = FastAPI(title="Python Active-Call", version="0.1.0")
|
app = FastAPI(title="Python Active-Call", version="0.1.0")
|
||||||
|
_WEB_CLIENT_PATH = Path(__file__).resolve().parent.parent / "examples" / "web_client.html"
|
||||||
|
|
||||||
# Configure CORS
|
# Configure CORS
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
@@ -99,6 +101,22 @@ async def health_check():
|
|||||||
return {"status": "healthy", "sessions": len(active_sessions)}
|
return {"status": "healthy", "sessions": len(active_sessions)}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
async def web_client_root():
|
||||||
|
"""Serve the web client."""
|
||||||
|
if not _WEB_CLIENT_PATH.exists():
|
||||||
|
raise HTTPException(status_code=404, detail="Web client not found")
|
||||||
|
return FileResponse(_WEB_CLIENT_PATH)
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/client")
|
||||||
|
async def web_client_alias():
|
||||||
|
"""Alias for the web client."""
|
||||||
|
if not _WEB_CLIENT_PATH.exists():
|
||||||
|
raise HTTPException(status_code=404, detail="Web client not found")
|
||||||
|
return FileResponse(_WEB_CLIENT_PATH)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/iceservers")
|
@app.get("/iceservers")
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
"""Static web client server (port 8100 by default)."""
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from fastapi import FastAPI, HTTPException
|
|
||||||
from fastapi.responses import FileResponse
|
|
||||||
import uvicorn
|
|
||||||
|
|
||||||
WEB_CLIENT_PATH = Path(__file__).resolve().parent.parent / "examples" / "web_client.html"
|
|
||||||
|
|
||||||
app = FastAPI(title="Python Active-Call Web Client", version="0.1.0")
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
async def web_client():
|
|
||||||
"""Serve the web client."""
|
|
||||||
if not WEB_CLIENT_PATH.exists():
|
|
||||||
raise HTTPException(status_code=404, detail="Web client not found")
|
|
||||||
return FileResponse(WEB_CLIENT_PATH)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
uvicorn.run(
|
|
||||||
"app.web_client:app",
|
|
||||||
host="0.0.0.0",
|
|
||||||
port=8100,
|
|
||||||
reload=True,
|
|
||||||
log_level="info",
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user