summaryrefslogtreecommitdiffstats
path: root/webapp/app/views.py
diff options
context:
space:
mode:
authorAaron Perley <aaron.perley@gmail.com>2016-10-11 02:03:49 -0400
committerAaron Perley <aaron.perley@gmail.com>2016-10-11 02:03:49 -0400
commit2d37dd487f0571ce94a0e4e966931dd6697d685f (patch)
tree3a55e17552c4c5cb2a26f23c4613d0d7ca0dce28 /webapp/app/views.py
parent198dcfc6f43724a3240496259e2bcda8b6bf6e8d (diff)
downloadbridge-2d37dd487f0571ce94a0e4e966931dd6697d685f.tar.zst
Add event passing between webapp and show
Diffstat (limited to 'webapp/app/views.py')
-rw-r--r--webapp/app/views.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/webapp/app/views.py b/webapp/app/views.py
index 4aa2c05..1c68688 100644
--- a/webapp/app/views.py
+++ b/webapp/app/views.py
@@ -1,11 +1,9 @@
from flask import render_template, request
-from app import app, sio
+from app import app, sio, send_queue, recv_queue
import time
import threading
-thread = None
-
@app.route('/')
@app.route('/index')
def index():
@@ -22,6 +20,14 @@ def connect(sid, environ):
@sio.on('spawn', namespace='/spawn')
def message(sid, data):
print("message ", data)
+ send_queue.put(('spawn', data))
+
+@sio.on('ready', namespace='/spawn')
+def ready(sid):
+ print("got ready message from ", sid)
+ for event in received_events:
+ print "sending missed event", event
+ sio.emit(event[0], event[1], room=sid, namespace='/spawn')
@sio.on('disconnect', namespace='/spawn')
def disconnect(sid):
@@ -29,9 +35,12 @@ def disconnect(sid):
connections.remove(sid)
+received_events = []
+def recv_events():
+ while True:
+ event = recv_queue.get()
+ sio.emit(event[0], event[1], namespace='/spawn')
+ received_events.append(event)
-def add_creature():
- time.sleep(5)
- sio.emit('new creature', {'name': 'fish1'}, namespace='/spawn')
-thread = sio.start_background_task(add_creature)
+thread = sio.start_background_task(recv_events)