diff --git a/lib/tfw/networking/server/zmq_websocket_proxy.py b/lib/tfw/networking/server/zmq_websocket_proxy.py index 3fc5bff..7a38e4a 100644 --- a/lib/tfw/networking/server/zmq_websocket_proxy.py +++ b/lib/tfw/networking/server/zmq_websocket_proxy.py @@ -17,13 +17,10 @@ class ZMQWebSocketProxy(WebSocketHandler): def initialize(self, **kwargs): # pylint: disable=arguments-differ self._event_handler_connector = kwargs['event_handler_connector'] - self.init_callback_lists_from( - kwargs, - [ - 'message_handlers', - 'proxy_filters' - ] - ) + self._message_handlers = kwargs.get('message_handlers', []) + self._frontend_message_handlers = kwargs.get('frontend_message_handlers', []) + self._eventhandler_message_handlers = kwargs.get('eventhandler_message_handlers', []) + self._proxy_filters = kwargs.get('proxy_filters', []) self.proxy_eventhandler_to_websocket = TFWProxy( self.send_eventhandler_message, @@ -36,22 +33,16 @@ class ZMQWebSocketProxy(WebSocketHandler): self.subscribe_proxy_callbacks() - def init_callback_lists_from(self, init_kwargs, callback_lists): - for callback_list in callback_lists: - setattr( - self, - f'_{callback_list}', - init_kwargs.get(callback_list, []) - ) - def subscribe_proxy_callbacks(self): - proxies = ( - self.proxy_eventhandler_to_websocket, - self.proxy_websocket_to_eventhandler + self.proxy_websocket_to_eventhandler.subscribe_proxy_callbacks_and_filters( + self._eventhandler_message_handlers + self._message_handlers, + self._proxy_filters + ) + + self.proxy_eventhandler_to_websocket.subscribe_proxy_callbacks_and_filters( + self._frontend_message_handlers + self._message_handlers, + self._proxy_filters ) - for proxy in proxies: - proxy.proxy_filters.subscribe_callbacks(*self._proxy_filters) - proxy.proxy_callbacks.subscribe_callbacks(*self._message_handlers) def prepare(self): ZMQWebSocketProxy.instances.add(self) @@ -139,3 +130,7 @@ class TFWProxy: LOG.debug('Broadcasting message: %s', message) self.to_source(message) self.to_destination(message) + + def subscribe_proxy_callbacks_and_filters(self, proxy_callbacks, proxy_filters): + self.proxy_callbacks.subscribe_callbacks(*proxy_callbacks) + self.proxy_filters.subscribe_callbacks(*proxy_filters)