Ramesh-vani commited on
Commit
89c73c8
·
verified ·
1 Parent(s): e183787

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -33,7 +33,7 @@ async def execute_command(websocket, project_name, command):
33
  response = f"Command executed:\n\nOutput:\n{output.decode('utf-8')}\nError:\n{error.decode('utf-8')}"
34
  websockets.broadcast(connected, response)
35
  except Exception as e:
36
- websockets.broadcast(connected, response)
37
 
38
  async def create_file_structure(websocket, data, base_path='.'):
39
  if data['type'] == 'folder':
@@ -213,7 +213,8 @@ async def handler(websocket):
213
  # Receive and parse the "init" event from the UI.
214
  message = await websocket.recv()
215
  event = json.loads(message)
216
- assert event["type"] == "init"
 
217
 
218
  if "join" in event:
219
  # Second player joins an existing game.
@@ -221,10 +222,25 @@ async def handler(websocket):
221
  elif "watch" in event:
222
  # Spectator watches an existing game.
223
  await watch(websocket, event["watch"])
 
 
 
224
  else:
225
  # First player starts a new game.
226
  await start(websocket, message)
227
 
 
 
 
 
 
 
 
 
 
 
 
 
228
 
229
  async def main():
230
  # Set the stop condition when receiving SIGTERM.
 
33
  response = f"Command executed:\n\nOutput:\n{output.decode('utf-8')}\nError:\n{error.decode('utf-8')}"
34
  websockets.broadcast(connected, response)
35
  except Exception as e:
36
+ websockets.broadcast(connected, e)
37
 
38
  async def create_file_structure(websocket, data, base_path='.'):
39
  if data['type'] == 'folder':
 
213
  # Receive and parse the "init" event from the UI.
214
  message = await websocket.recv()
215
  event = json.loads(message)
216
+ project_name = event["project_name"]
217
+ # assert event["type"] == "init"
218
 
219
  if "join" in event:
220
  # Second player joins an existing game.
 
222
  elif "watch" in event:
223
  # Spectator watches an existing game.
224
  await watch(websocket, event["watch"])
225
+ elif "cmd" in event:
226
+
227
+ await execute_command(websocket, event["project_name"], event["command"])
228
  else:
229
  # First player starts a new game.
230
  await start(websocket, message)
231
 
232
+ # assert event["type"] == "cmd"
233
+
234
+ # if "cmd" in event:
235
+ # # Second player joins an existing game.
236
+ # await execute_command(websocket, project_name, event["command"])
237
+ # elif "watch" in event:
238
+ # # Spectator watches an existing game.
239
+ # await watch(websocket, event["watch"])
240
+ # else:
241
+ # # First player starts a new game.
242
+ # await start(websocket, message)
243
+
244
 
245
  async def main():
246
  # Set the stop condition when receiving SIGTERM.