def __on_message(message: WebSocketMessage) -> None: logger.info('Incoming Message', message.as_dict()) try: handler = web_socket_message_handler_map.get(message.label, None) if handler: handler.handle(message) except Exception as e: logger.error(e)
def send(self, web_socket_message: WebSocketMessage) -> None: self.__logger.info('Outgoing Message', web_socket_message.as_dict()) serialized = str(web_socket_message.code) array_part = [ x for x in [web_socket_message.label, web_socket_message.payload] if x ] if array_part: serialized += json.dumps(array_part) self.__ws.send(serialized)