Merge pull request #2 from avatao-content/fsmupdate

Implement FSM status updates to frontend
This commit is contained in:
Bokros Bálint 2018-01-29 11:12:21 +01:00 committed by GitHub
commit 3fb29763f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import logging
import json
from tornado.websocket import WebSocketHandler
from util import parse_anchor_from_message
@ -24,6 +24,11 @@ class ZMQWebSocketHandler(WebSocketHandler):
def on_message(self, message):
logging.debug('Received on WebSocket: {}'.format(message))
fsm.trigger(parse_anchor_from_message(message), message=message)
anchor = 'FSMUpdate'
response = { 'anchor': anchor,
'data': { 'current_state': fsm.state,
'valid_transitions': [{'trigger': trigger} for trigger in fsm.machine.get_triggers()]}}
self.send_message(json.dumps(response), anchor)
def send_message(self, message: str, anchor: str = None):
event_handler_connector.send_message(message, anchor)