mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 12:42:55 +00:00 
			
		
		
		
	Implement EventHandler command mirroring (EH -> EH communication)
This commit is contained in:
		@@ -21,12 +21,23 @@ class ZMQWebSocketHandler(WebSocketHandler):
 | 
				
			|||||||
        log.debug('WebSocket connection initiated')
 | 
					        log.debug('WebSocket connection initiated')
 | 
				
			||||||
        self._event_handler_connector.register_callback(self.zmq_callback)
 | 
					        self._event_handler_connector.register_callback(self.zmq_callback)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @classmethod
 | 
				
			||||||
    def zmq_callback(msg_parts):
 | 
					    def zmq_callback(cls, msg_parts):
 | 
				
			||||||
 | 
					        keyhandlers = {'mirror': cls.mirror}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        key, data = deserialize_all(*msg_parts)
 | 
					        key, data = deserialize_all(*msg_parts)
 | 
				
			||||||
        log.debug('Received on pull socket: {}'.format(data))
 | 
					        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)
 | 
					                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):
 | 
					    def on_message(self, message):
 | 
				
			||||||
        log.debug('Received on WebSocket: {}'.format(message))
 | 
					        log.debug('Received on WebSocket: {}'.format(message))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user