|
@ -73,9 +73,8 @@ class GatewayClient(LoggingClass): |
|
|
self._heartbeat_acknowledged = True |
|
|
self._heartbeat_acknowledged = True |
|
|
|
|
|
|
|
|
# Latency |
|
|
# Latency |
|
|
self._last_send = time.perf_counter() |
|
|
self._last_heartbeat = 0 |
|
|
self._last_ack = time.perf_counter() |
|
|
self.latency = -1 |
|
|
self.latency = float('inf') |
|
|
|
|
|
|
|
|
|
|
|
def send(self, op, data): |
|
|
def send(self, op, data): |
|
|
self.limiter.check() |
|
|
self.limiter.check() |
|
@ -96,18 +95,12 @@ class GatewayClient(LoggingClass): |
|
|
self._heartbeat_acknowledged = True |
|
|
self._heartbeat_acknowledged = True |
|
|
self.ws.close(status=4000) |
|
|
self.ws.close(status=4000) |
|
|
return |
|
|
return |
|
|
else: |
|
|
self._last_heartbeat = time.time() |
|
|
self._last_send = time.perf_counter() |
|
|
|
|
|
|
|
|
|
|
|
self._send(OPCode.HEARTBEAT, self.seq) |
|
|
self._send(OPCode.HEARTBEAT, self.seq) |
|
|
self._heartbeat_acknowledged = False |
|
|
self._heartbeat_acknowledged = False |
|
|
gevent.sleep(interval / 1000) |
|
|
gevent.sleep(interval / 1000) |
|
|
|
|
|
|
|
|
def ack(self): |
|
|
|
|
|
ack_time = time.perf_counter() |
|
|
|
|
|
self._last_ack = ack_time |
|
|
|
|
|
self.latency = ack_time - self._last_send |
|
|
|
|
|
|
|
|
|
|
|
def handle_dispatch(self, packet): |
|
|
def handle_dispatch(self, packet): |
|
|
obj = GatewayEvent.from_dispatch(self.client, packet) |
|
|
obj = GatewayEvent.from_dispatch(self.client, packet) |
|
|
self.log.debug('GatewayClient.handle_dispatch %s', obj.__class__.__name__) |
|
|
self.log.debug('GatewayClient.handle_dispatch %s', obj.__class__.__name__) |
|
@ -121,7 +114,7 @@ class GatewayClient(LoggingClass): |
|
|
def handle_heartbeat_acknowledge(self, _): |
|
|
def handle_heartbeat_acknowledge(self, _): |
|
|
self.log.debug('Received HEARTBEAT_ACK') |
|
|
self.log.debug('Received HEARTBEAT_ACK') |
|
|
self._heartbeat_acknowledged = True |
|
|
self._heartbeat_acknowledged = True |
|
|
self.ack() |
|
|
self.latency = int((time.time() - self._last_heartbeat) * 1000) |
|
|
|
|
|
|
|
|
def handle_reconnect(self, _): |
|
|
def handle_reconnect(self, _): |
|
|
self.log.warning('Received RECONNECT request, forcing a fresh reconnect') |
|
|
self.log.warning('Received RECONNECT request, forcing a fresh reconnect') |
|
|