radames commited on
Commit
64e241d
1 Parent(s): 46bd9ac

skip if no data

Browse files
Files changed (1) hide show
  1. app_init.py +6 -15
app_init.py CHANGED
@@ -43,11 +43,7 @@ def init_app(app: FastAPI, user_data: UserData, args: Args, pipeline):
43
  await websocket.send_json(
44
  {"status": "connected", "message": "Connected", "userId": str(user_id)}
45
  )
46
- await websocket.send_json(
47
- {
48
- "status": "send_frame",
49
- }
50
- )
51
  await handle_websocket_data(user_id, websocket)
52
  except WebSocketDisconnect as e:
53
  logging.error(f"WebSocket Error: {e}, {user_id}")
@@ -73,13 +69,12 @@ def init_app(app: FastAPI, user_data: UserData, args: Args, pipeline):
73
  params = SimpleNamespace(**params.dict())
74
  if info.input_mode == "image":
75
  image_data = await websocket.receive_bytes()
 
 
 
76
  params.image = bytes_to_pil(image_data)
77
  await user_data.update_data(user_id, params)
78
- await websocket.send_json(
79
- {
80
- "status": "wait",
81
- }
82
- )
83
  if args.timeout > 0 and time.time() - last_time > args.timeout:
84
  await websocket.send_json(
85
  {
@@ -112,11 +107,7 @@ def init_app(app: FastAPI, user_data: UserData, args: Args, pipeline):
112
  while True:
113
  params = await user_data.get_latest_data(user_id)
114
  if not vars(params) or params.__dict__ == last_params.__dict__:
115
- await websocket.send_json(
116
- {
117
- "status": "send_frame",
118
- }
119
- )
120
  await asyncio.sleep(0.1)
121
  continue
122
 
 
43
  await websocket.send_json(
44
  {"status": "connected", "message": "Connected", "userId": str(user_id)}
45
  )
46
+ await websocket.send_json({"status": "send_frame"})
 
 
 
 
47
  await handle_websocket_data(user_id, websocket)
48
  except WebSocketDisconnect as e:
49
  logging.error(f"WebSocket Error: {e}, {user_id}")
 
69
  params = SimpleNamespace(**params.dict())
70
  if info.input_mode == "image":
71
  image_data = await websocket.receive_bytes()
72
+ if len(image_data) == 0:
73
+ await websocket.send_json({"status": "send_frame"})
74
+ continue
75
  params.image = bytes_to_pil(image_data)
76
  await user_data.update_data(user_id, params)
77
+ await websocket.send_json({"status": "wait"})
 
 
 
 
78
  if args.timeout > 0 and time.time() - last_time > args.timeout:
79
  await websocket.send_json(
80
  {
 
107
  while True:
108
  params = await user_data.get_latest_data(user_id)
109
  if not vars(params) or params.__dict__ == last_params.__dict__:
110
+ await websocket.send_json({"status": "send_frame"})
 
 
 
 
111
  await asyncio.sleep(0.1)
112
  continue
113