feat(realtime): add ping/pong heartbeat and watchdog reconnect
Some checks failed
CI / test (push) Failing after 20s
Some checks failed
CI / test (push) Failing after 20s
- support ping incoming event and pong outgoing response - add web heartbeat interval to keep ws alive - add stale-connection watchdog to force reconnect on missing pong
This commit is contained in:
@@ -40,6 +40,15 @@ async def websocket_gateway(websocket: WebSocket) -> None:
|
||||
raw_data = await websocket.receive_json()
|
||||
try:
|
||||
event = IncomingRealtimeEvent.model_validate(raw_data)
|
||||
if event.event == "ping":
|
||||
await websocket.send_json(
|
||||
OutgoingRealtimeEvent(
|
||||
event="pong",
|
||||
payload={},
|
||||
timestamp=datetime.now(timezone.utc),
|
||||
).model_dump(mode="json")
|
||||
)
|
||||
continue
|
||||
await _dispatch_event(db, user.id, event)
|
||||
except ValidationError:
|
||||
await websocket.send_json(
|
||||
|
||||
Reference in New Issue
Block a user