-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (40 loc) · 1.48 KB
/
main.py
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
from signal import SIGINT, signal, SIGTERM
from socket import gethostname
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from server.app import app
from server.layouts import main_layout
from server.viewer import make_viewers, streamers_dict
app.layout = html.Div([dcc.Location(id='url', refresh=False),
html.Div(id='page-content', children=main_layout)])
layout = main_layout
import server.callbacks
@app.callback(Output('page-content', 'children'),
Input('url', 'pathname'),
State('page-content', 'children'))
def display_page(pathname, current_layout):
global layout
if pathname == '/':
for name in streamers_dict.keys():
streamers_dict[name].flag_stream = False
streamers_dict[name]._camera = None
return layout
elif pathname == '/viewer':
layout = current_layout
return make_viewers()
else:
return dash.no_update
if __name__ == '__main__':
signal(SIGINT, server.callbacks.exit_handler)
signal(SIGTERM, server.callbacks.exit_handler)
PORT = 8080
IP = "0.0.0.0"
# noinspection HttpUrlsUsage
print(f"http://{gethostname():s}:{PORT:d}/")
app.logger.disabled = True
app.run_server(debug=False, host=IP, port=PORT, threaded=True)
# todo: validate data saving reliability (it seems sometimes data isn't saved)
# todo: persistant counter
# todo: camera logs in GUI