So I'm transfering from node into FastAPI (Because it's more convinient for me) And I have a webpage (full code here), which was working in node, but when transferred to FastAPI only starting websocket messages get through, the one in loop get lost (though problem is only with this particular page, other pages in project receives them). Here's FastAPI code:
@app.websocket("/websocket")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
await websocket.send_json({"event": "infobar", "content": info_bar})
await websocket.send_json({"event": "show_emblem", "value": emblem_visible})
await websocket.send_json({"event": "predefs", "content": predefs})
await websocket.send_json({"event": "candidates", "content": candidates})
await websocket.send_json({"event": "timer_state", "state": timer.__dict__()})
while True:
data = await websocket.receive_json()
print(data)
if data["event"] == "timer":
if data["type"] == "start" and not timer.running:
timer.running = True
timer.started_at = datetime.datetime.now()
await websocket.send_json({"event": "timer_state", "state": timer.__dict__()})
elif data["type"] == "stop":
UpdateTimer()
timer.running = False
await websocket.send_json({"event": "timer_state", "state": timer.__dict__()})
elif["type"] == "set":
timer.running = False
timer.time = int(data["time"])
await websocket.send_json({"event": "timer_state", "state": timer.__dict__()})
else:
print(data)
await websocket.send_json({"event": "Test_event", "content": "Missing"})
print("Dispatching")