1
0
дзеркало https://github.com/avatao-content/baseimage-tutorial-framework синхронізовано 2026-03-26 17:46:54 +00:00

Implement EventHandler command mirroring (EH -> EH communication)

Цей коміт міститься в:
Kristóf Tóth
2018-03-14 14:08:48 +01:00
джерело 0361092f37
коміт 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:
instance.write_message(data)
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))