Add websocket event stream for sim updates.

As a proof of concept this only covers the flight positions.
This commit is contained in:
Dan Albert
2022-02-16 01:28:10 -08:00
parent 350f08be2f
commit 21f7912458
14 changed files with 150 additions and 15 deletions

View File

@@ -0,0 +1,21 @@
from fastapi import APIRouter
from fastapi.encoders import jsonable_encoder
from starlette.websockets import WebSocket
from .eventstream import EventStream
from .models import GameUpdateEventsJs
from .. import GameContext
router = APIRouter()
@router.websocket("/eventstream")
async def event_stream(websocket: WebSocket) -> None:
await websocket.accept()
while True:
if not (events := await EventStream.get()).empty:
await websocket.send_json(
jsonable_encoder(
GameUpdateEventsJs.from_events(events, GameContext.get())
)
)