-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (49 loc) · 1.66 KB
/
app.py
File metadata and controls
73 lines (49 loc) · 1.66 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# app.py
from fastapi import FastAPI
import socketio
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from data import sample
#from fastapi_socketio import SocketManager
app = FastAPI()
# sio = socketio.Server(logger=False);
# socket_app = socketio.WSGIApp(sio, static_files={'/': 'viewer/index.html'})
sio = socketio.AsyncServer(logger=False, async_mode='asgi')
socket_app = socketio.ASGIApp(sio, static_files={'/': 'viewer/index.html'})
background_task_started = False
#sio = SocketManager(app=app)
#sio.attach(app)
def background_task():
print("background task")
@sio.on('disconnect')
def test_disconnect(sid):
print('Client disconnected')
@app.get("/hello")
def root():
return {"message": "Hello World"}
app.mount("/static", StaticFiles(directory="viewer"), name="static")
app.mount("/data", StaticFiles(directory="data"), name="data")
app.mount('/', socket_app)
#@app.get("/viewer", response_class=HTMLResponse)
#async def index():
# with open('viewer/index.html') as f:
# return f.read()
@sio.on('run')
async def handle_join(sid, *args, **kwargs):
print("JOINING")
await sample.run(sio)
#return sample.run(sio)
# print(sid)
# print(args)
# await sio.emit('lobby', 'User joined')
# @sio.on('test')
# async def test(sid, *args, **kwargs):
# await sio.emit('hey', 'joe')
#app.router.add_get('/', index)
if __name__ == '__main__':
import logging
import sys
logging.basicConfig(level=logging.DEBUG,
stream=sys.stdout)
import uvicorn
uvicorn.run("app:app", host='0.0.0.0', port=8000, reload=True, debug=False,log_level="info")