summaryrefslogtreecommitdiffstats
path: root/webapp/app/views.py
diff options
context:
space:
mode:
authorRaymond Hogenson <rayhogenson@openmailbox.org>2016-10-15 10:06:20 -0400
committerRaymond Hogenson <rayhogenson@openmailbox.org>2016-10-15 10:06:20 -0400
commitc4999bbbfdbca65986e876ac78863041e85cfbe4 (patch)
treeb3f300c16fb369061ea7139c3e3684e7eac8a924 /webapp/app/views.py
parent2dd0795104b14fbb7aeee95f9f6bcf349f119960 (diff)
parentad2fbe28d4e345c9b100f47eef2da0b8f76ff9a5 (diff)
downloadbridge-c4999bbbfdbca65986e876ac78863041e85cfbe4.tar.zst
Merge branch 'master' of github.com:rayhogenson/bridge
Diffstat (limited to 'webapp/app/views.py')
-rw-r--r--webapp/app/views.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/webapp/app/views.py b/webapp/app/views.py
index 4aa2c05..b03f6ab 100644
--- a/webapp/app/views.py
+++ b/webapp/app/views.py
@@ -1,17 +1,19 @@
-from flask import render_template, request
-from app import app, sio
+from flask import render_template, request, send_from_directory
+from app import app, sio, send_queue, recv_queue
import time
import threading
-thread = None
-
@app.route('/')
@app.route('/index')
def index():
return render_template('index.html',
title='F16 Group1')
+@app.route('/static/<path:path>')
+def send_static(path):
+ return send_from_directory('static', path)
+
connections = set()
@sio.on('connect', namespace='/spawn')
@@ -22,6 +24,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 +39,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)