1 from ws4py.client.threadedclient import WebSocketClient
10 class EventClient(WebSocketClient):
11 def __init__(self, url, filters, on_event):
13 if re.match(r'(?i)^(true|1|yes)$',
14 config.get('ARVADOS_API_HOST_INSECURE', 'no')):
15 ssl_options={'cert_reqs': ssl.CERT_NONE}
17 ssl_options={'cert_reqs': ssl.CERT_REQUIRED}
19 super(EventClient, self).__init__(url, ssl_options)
20 self.filters = filters
21 self.on_event = on_event
24 self.send(json.dumps({"method": "subscribe", "filters": self.filters}))
26 def received_message(self, m):
27 self.on_event(json.loads(str(m)))
29 def subscribe(api, filters, on_event):
30 url = "{}?api_token={}".format(api._rootDesc['websocketUrl'], config.get('ARVADOS_API_TOKEN'))
31 ws = EventClient(url, filters, on_event)