-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
32 lines (22 loc) · 782 Bytes
/
server.py
File metadata and controls
32 lines (22 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from fastapi import FastAPI, WebSocket, Response, WebSocketDisconnect
from websockets.exceptions import ConnectionClosed
from handler.conn import ConnectionHandler, Conn
app = FastAPI()
@app.websocket("/session")
async def session(ws: WebSocket):
conn = await Conn.create(ws)
await ConnectionHandler.join(conn)
while True:
try:
client_event = await conn.receive()
await ConnectionHandler.publish_client_event(conn, client_event)
except (WebSocketDisconnect, ConnectionClosed) as e:
# 연결 종료됨
break
await ConnectionHandler.quit(conn)
@app.get("/")
def health_check():
return Response()
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)