From 1b65bd4d3d3d22046fc344401c01055724c3cf20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 29 Jun 2018 10:54:08 +0200 Subject: [PATCH] Implement message broadcasting --- lib/tfw/networking/server/zmq_websocket_handler.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tfw/networking/server/zmq_websocket_handler.py b/lib/tfw/networking/server/zmq_websocket_handler.py index 7eafe53..9456ca4 100644 --- a/lib/tfw/networking/server/zmq_websocket_handler.py +++ b/lib/tfw/networking/server/zmq_websocket_handler.py @@ -23,7 +23,8 @@ class TFWProxy: self.proxy_filters.subscribe_callback(validate_message) self.keyhandlers = { - 'mirror': self.mirror + 'mirror': self.mirror, + 'broadcast': self.broadcast } def __call__(self, message): @@ -38,16 +39,23 @@ class TFWProxy: if message['key'] not in self.keyhandlers: self.to_destination(message) else: + handler = self.keyhandlers[message['key']] try: - self.keyhandlers[message['key']](message) + handler(message) except KeyError: - LOG.error('Invalid mirror message format! Ignoring.') + LOG.error('Invalid "%s" message format! Ignoring.', handler.__name__) def mirror(self, message): message = message['data'] LOG.debug('Mirroring message: %s', message) self.to_source(message) + def broadcast(self, message): + message = message['data'] + LOG.debug('Broadcasting message: %s', message) + self.to_source(message) + self.to_destination(message) + class ZMQWebSocketProxy(WebSocketHandler): instances = set()