diff options
| author | Aaron Perley <aaron.perley@gmail.com> | 2016-10-17 14:05:57 -0400 |
|---|---|---|
| committer | Aaron Perley <aaron.perley@gmail.com> | 2016-10-17 14:05:57 -0400 |
| commit | ebda59b316159f7e568c634cc5d906447928f973 (patch) | |
| tree | 285c1496d7b31c4b04abc4aa0a3cf3a520ad8936 /webapp/app/views.py | |
| parent | Bugfixes (diff) | |
| download | bridge-ebda59b316159f7e568c634cc5d906447928f973.tar.zst | |
Make fish enable/disable state more robust
Diffstat (limited to 'webapp/app/views.py')
| -rw-r--r-- | webapp/app/views.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/webapp/app/views.py b/webapp/app/views.py index b03f6ab..a13bf12 100644 --- a/webapp/app/views.py +++ b/webapp/app/views.py @@ -28,23 +28,34 @@ def message(sid, 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.emit('fish state', fish_state, room=sid, namespace='/spawn') @sio.on('disconnect', namespace='/spawn') def disconnect(sid): print('disconnect', sid) connections.remove(sid) +fish_state = { + 'jellyfish': 0, + 'dolphin': 0, + 'boat': 0, + 'nemo': 0, + 'dory': 0, + 'whale': 0, + 'eel': 0, + 'stingray': 0, + 'shark': 0 +} -received_events = [] def recv_events(): while True: event = recv_queue.get() - sio.emit(event[0], event[1], namespace='/spawn') - received_events.append(event) + if event[0] == 'enable image': + fish_state[event[1]['name']] = 1 + elif event[0] == 'disable image': + fish_state[event[1]['name']] = 0 + + sio.emit('fish state', fish_state, namespace='/spawn') thread = sio.start_background_task(recv_events) |
