mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:31:31 +00:00
Implement message broadcasting
This commit is contained in:
parent
f8233d51a9
commit
1b65bd4d3d
@ -23,7 +23,8 @@ class TFWProxy:
|
|||||||
self.proxy_filters.subscribe_callback(validate_message)
|
self.proxy_filters.subscribe_callback(validate_message)
|
||||||
|
|
||||||
self.keyhandlers = {
|
self.keyhandlers = {
|
||||||
'mirror': self.mirror
|
'mirror': self.mirror,
|
||||||
|
'broadcast': self.broadcast
|
||||||
}
|
}
|
||||||
|
|
||||||
def __call__(self, message):
|
def __call__(self, message):
|
||||||
@ -38,16 +39,23 @@ class TFWProxy:
|
|||||||
if message['key'] not in self.keyhandlers:
|
if message['key'] not in self.keyhandlers:
|
||||||
self.to_destination(message)
|
self.to_destination(message)
|
||||||
else:
|
else:
|
||||||
|
handler = self.keyhandlers[message['key']]
|
||||||
try:
|
try:
|
||||||
self.keyhandlers[message['key']](message)
|
handler(message)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOG.error('Invalid mirror message format! Ignoring.')
|
LOG.error('Invalid "%s" message format! Ignoring.', handler.__name__)
|
||||||
|
|
||||||
def mirror(self, message):
|
def mirror(self, message):
|
||||||
message = message['data']
|
message = message['data']
|
||||||
LOG.debug('Mirroring message: %s', message)
|
LOG.debug('Mirroring message: %s', message)
|
||||||
self.to_source(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):
|
class ZMQWebSocketProxy(WebSocketHandler):
|
||||||
instances = set()
|
instances = set()
|
||||||
|
Loading…
Reference in New Issue
Block a user