Ramesh-vani commited on
Commit
6e1f7b2
·
verified ·
1 Parent(s): a8cd64d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -1207,6 +1207,7 @@ async def start(websocket,events):
1207
  user = User()
1208
  connected = {websocket}
1209
  process_ids = []
 
1210
 
1211
  join_key = secrets.token_urlsafe(12)
1212
  JOIN[join_key] = user, connected
@@ -1261,22 +1262,34 @@ async def handler(websocket):
1261
 
1262
  """
1263
  # Receive and parse the "init" event from the UI.
1264
- message = await websocket.recv()
1265
- event = json.loads(message)
1266
- # print(event)
1267
- # project_name = event["project_name"]
1268
- # assert event["type"] == "init"
1269
- if event["type"] == "init":
1270
- if "join" in event:
1271
- # Second player joins an existing game.
1272
- await join(websocket, event["join"])
1273
- else:
1274
- # First player starts a new game.
1275
- await start(websocket, message)
1276
- elif event["type"] == "cmd":
1277
- # print('executing commad')
1278
- # Execute a command in the project folder.
1279
- await execute_command(websocket, event["project_name"], event["command"])
 
 
 
 
 
 
 
 
 
 
 
 
1280
 
1281
  async def main():
1282
  # Set the stop condition when receiving SIGTERM.
 
1207
  user = User()
1208
  connected = {websocket}
1209
  process_ids = []
1210
+
1211
 
1212
  join_key = secrets.token_urlsafe(12)
1213
  JOIN[join_key] = user, connected
 
1262
 
1263
  """
1264
  # Receive and parse the "init" event from the UI.
1265
+ try:
1266
+ message_parts = {}
1267
+ async for message in websocket:
1268
+ data = json.loads(message)
1269
+ msg_id = data['msg_id']
1270
+ part = data['part']
1271
+
1272
+ if msg_id not in message_parts:
1273
+ message_parts[msg_id] = []
1274
+ message_parts[msg_id].append(part)
1275
+
1276
+ if data['end']:
1277
+ full_message = ''.join(message_parts[msg_id])
1278
+ print(f"Received full message: {full_message}")
1279
+
1280
+ event = json.loads(full_message)
1281
+
1282
+ if event["type"] == "init":
1283
+ if "join" in event:
1284
+ # Second player joins an existing game.
1285
+ await join(websocket, event["join"])
1286
+ else:
1287
+ # First player starts a new game.
1288
+ await start(websocket, full_message)
1289
+ elif event["type"] == "cmd":
1290
+ # print('executing commad')
1291
+ # Execute a command in the project folder.
1292
+ await execute_command(websocket, event["project_name"], event["command"])
1293
 
1294
  async def main():
1295
  # Set the stop condition when receiving SIGTERM.