Commit 847ec31f authored by Kento HASEGAWA's avatar Kento HASEGAWA

Add support for websocket updating of multiple clients

parent 7a4ee367
...@@ -32,7 +32,7 @@ app_args = {} ...@@ -32,7 +32,7 @@ app_args = {}
questions = None questions = None
clients = None clients = None
current_seed = 1 current_seed = 1
wsq = None wsq = {}
def load_questions(): def load_questions():
global app_args global app_args
...@@ -213,7 +213,9 @@ def post(): ...@@ -213,7 +213,9 @@ def post():
with open(save_file_path, "w") as fp: with open(save_file_path, "w") as fp:
json.dump(dat, fp, indent=4) json.dump(dat, fp, indent=4)
wsq.put(dat) for k, v in wsq.items():
if v is not None:
v.put(dat)
res = {"status": "OK"} res = {"status": "OK"}
...@@ -600,14 +602,15 @@ def ws(): ...@@ -600,14 +602,15 @@ def ws():
if request.environ.get('wsgi.websocket'): if request.environ.get('wsgi.websocket'):
ws = request.environ['wsgi.websocket'] ws = request.environ['wsgi.websocket']
ws_id = time.time()
wsq[ws_id] = Queue()
while True: while True:
if wsq is None: data = wsq[ws_id].get()
time.sleep(1) str_data = json.dumps(data)
continue ws.send(str_data)
else:
data = wsq.get() wsq[ws_id] = None
str_data = json.dumps(data)
ws.send(str_data)
@app.route("/") @app.route("/")
def index(): def index():
...@@ -653,9 +656,6 @@ def init_system(): ...@@ -653,9 +656,6 @@ def init_system():
if questions is None: if questions is None:
load_questions() load_questions()
if wsq is None:
wsq = Queue()
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="PYNQ control panel.") parser = argparse.ArgumentParser(description="PYNQ control panel.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment