mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-26 12:51:32 +00:00
Add frontend/eventhandler message callback capabilities to ZMQWSProxy
This commit is contained in:
parent
f6cc7ae495
commit
d2084b2e51
@ -17,13 +17,10 @@ class ZMQWebSocketProxy(WebSocketHandler):
|
|||||||
def initialize(self, **kwargs): # pylint: disable=arguments-differ
|
def initialize(self, **kwargs): # pylint: disable=arguments-differ
|
||||||
self._event_handler_connector = kwargs['event_handler_connector']
|
self._event_handler_connector = kwargs['event_handler_connector']
|
||||||
|
|
||||||
self.init_callback_lists_from(
|
self._message_handlers = kwargs.get('message_handlers', [])
|
||||||
kwargs,
|
self._frontend_message_handlers = kwargs.get('frontend_message_handlers', [])
|
||||||
[
|
self._eventhandler_message_handlers = kwargs.get('eventhandler_message_handlers', [])
|
||||||
'message_handlers',
|
self._proxy_filters = kwargs.get('proxy_filters', [])
|
||||||
'proxy_filters'
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.proxy_eventhandler_to_websocket = TFWProxy(
|
self.proxy_eventhandler_to_websocket = TFWProxy(
|
||||||
self.send_eventhandler_message,
|
self.send_eventhandler_message,
|
||||||
@ -36,22 +33,16 @@ class ZMQWebSocketProxy(WebSocketHandler):
|
|||||||
|
|
||||||
self.subscribe_proxy_callbacks()
|
self.subscribe_proxy_callbacks()
|
||||||
|
|
||||||
def init_callback_lists_from(self, init_kwargs, callback_lists):
|
def subscribe_proxy_callbacks(self):
|
||||||
for callback_list in callback_lists:
|
self.proxy_websocket_to_eventhandler.subscribe_proxy_callbacks_and_filters(
|
||||||
setattr(
|
self._eventhandler_message_handlers + self._message_handlers,
|
||||||
self,
|
self._proxy_filters
|
||||||
f'_{callback_list}',
|
|
||||||
init_kwargs.get(callback_list, [])
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def subscribe_proxy_callbacks(self):
|
self.proxy_eventhandler_to_websocket.subscribe_proxy_callbacks_and_filters(
|
||||||
proxies = (
|
self._frontend_message_handlers + self._message_handlers,
|
||||||
self.proxy_eventhandler_to_websocket,
|
self._proxy_filters
|
||||||
self.proxy_websocket_to_eventhandler
|
|
||||||
)
|
)
|
||||||
for proxy in proxies:
|
|
||||||
proxy.proxy_filters.subscribe_callbacks(*self._proxy_filters)
|
|
||||||
proxy.proxy_callbacks.subscribe_callbacks(*self._message_handlers)
|
|
||||||
|
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
ZMQWebSocketProxy.instances.add(self)
|
ZMQWebSocketProxy.instances.add(self)
|
||||||
@ -139,3 +130,7 @@ class TFWProxy:
|
|||||||
LOG.debug('Broadcasting message: %s', message)
|
LOG.debug('Broadcasting message: %s', message)
|
||||||
self.to_source(message)
|
self.to_source(message)
|
||||||
self.to_destination(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)
|
||||||
|
Loading…
Reference in New Issue
Block a user