def _subscribe_websocket(api, filters, on_event, last_log_id=None): endpoint = api._rootDesc.get('websocketUrl', None) if not endpoint: raise errors.FeatureNotEnabledError( "Server does not advertise a websocket endpoint") uri_with_token = "{}?api_token={}".format(endpoint, api.api_token) try: client = EventClient(uri_with_token, filters, on_event, last_log_id) except Exception: _logger.warn("Failed to connect to websockets on %s" % endpoint) raise else: return client
def _subscribe_websocket(api, filters, on_event): endpoint = api._rootDesc.get('websocketUrl', None) if not endpoint: raise errors.FeatureNotEnabledError( "Server does not advertise a websocket endpoint") uri_with_token = "{}?api_token={}".format(endpoint, api.api_token) client = EventClient(uri_with_token, filters, on_event) ok = False try: client.connect() ok = True return client finally: if not ok: client.close_connection()