Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,17 @@
|
|
1 |
-
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
|
|
2 |
from typing import Dict
|
3 |
app = FastAPI()
|
4 |
clients: Dict[str, WebSocket] = {}
|
5 |
@app.get("/clients")
|
6 |
def get_clients():
|
7 |
return list(clients.keys())
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
@app.websocket("/ws/{client_id}")
|
9 |
async def websocket_endpoint(websocket: WebSocket, client_id: str):
|
10 |
await websocket.accept()
|
|
|
1 |
+
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
2 |
+
from websockets import connect as websockets_connect
|
3 |
from typing import Dict
|
4 |
app = FastAPI()
|
5 |
clients: Dict[str, WebSocket] = {}
|
6 |
@app.get("/clients")
|
7 |
def get_clients():
|
8 |
return list(clients.keys())
|
9 |
+
@app.get("/send/{name}/{id}/{message}")
|
10 |
+
async def sendmsg(name,id,message):
|
11 |
+
async with websockets_connect("ws://localhost:7860"+name) as websocket:
|
12 |
+
await websocket.send(f"{id}:{message}")
|
13 |
+
return await websocket.recv()
|
14 |
+
|
15 |
@app.websocket("/ws/{client_id}")
|
16 |
async def websocket_endpoint(websocket: WebSocket, client_id: str):
|
17 |
await websocket.accept()
|