baseimage-tutorial-framework/src/app/handlers/zmq_websocket_handler.py

37 lines
1.1 KiB
Python
Raw Normal View History

import logging
from tornado.websocket import WebSocketHandler
from util import parse_anchor_from_message
# from buttons import fsm
from sql_injection_fsm import fsm
import event_handler_connector
class ZMQWebSocketHandler(WebSocketHandler):
def __init__(self, application, request, **kwargs):
super().__init__(application, request, **kwargs)
def open(self, *args, **kwargs):
def zmq_callback(msg_parts):
anchor, data = msg_parts
logging.debug('Received on pull socket: {}'.format(data.decode()))
self.write_message(data.decode())
event_handler_connector.register_callback(zmq_callback)
def on_message(self, message):
logging.debug('Received on WebSocket: {}'.format(message))
fsm.trigger(parse_anchor_from_message(message), message=message)
def send_message(self, message: str, anchor: str = None):
event_handler_connector.send_message(message, anchor)
def on_close(self):
pass
# much secure, very cors, wow
def check_origin(self, origin):
return True