mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 22:21:32 +00:00
Implement EventHandler command mirroring (EH -> EH communication)
This commit is contained in:
parent
0361092f37
commit
69f03f7615
@ -21,12 +21,23 @@ class ZMQWebSocketHandler(WebSocketHandler):
|
||||
log.debug('WebSocket connection initiated')
|
||||
self._event_handler_connector.register_callback(self.zmq_callback)
|
||||
|
||||
@staticmethod
|
||||
def zmq_callback(msg_parts):
|
||||
@classmethod
|
||||
def zmq_callback(cls, msg_parts):
|
||||
keyhandlers = {'mirror': cls.mirror}
|
||||
|
||||
key, data = deserialize_all(*msg_parts)
|
||||
log.debug('Received on pull socket: {}'.format(data))
|
||||
for instance in ZMQWebSocketHandler.instances:
|
||||
if key not in keyhandlers:
|
||||
for instance in cls.instances:
|
||||
instance.write_message(data)
|
||||
else:
|
||||
try: keyhandlers[key](data['data'])
|
||||
except KeyError: log.error('Invalid mirror message format! Ignoring.')
|
||||
|
||||
@classmethod
|
||||
def mirror(cls, data):
|
||||
key = data['key']
|
||||
cls._event_handler_connector.send_message({'data': data}, key)
|
||||
|
||||
def on_message(self, message):
|
||||
log.debug('Received on WebSocket: {}'.format(message))
|
||||
|
Loading…
Reference in New Issue
Block a user