feat(02-02): wire WebSocket broadcast loop and command dispatch
- Add broadcast_loop sending position ticks at 10Hz to all clients - Replace echo stub with play/pause/seek/load command dispatch to MPVEngine - Start broadcast_loop as asyncio task in lifespan, cancel on shutdown - Use get_engine callable to avoid circular import at module level
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from pathlib import Path
|
||||
@@ -27,8 +28,15 @@ async def lifespan(app: FastAPI):
|
||||
engine = MPVEngine(ao=ao)
|
||||
engine.start()
|
||||
app.state.engine = engine
|
||||
from lightsync.api.ws import broadcast_loop
|
||||
task = asyncio.create_task(broadcast_loop(lambda: engine))
|
||||
yield
|
||||
# Shutdown
|
||||
task.cancel()
|
||||
try:
|
||||
await task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
engine.stop()
|
||||
await registry.save()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user