From 8df8d323634d7323c9d109806ad16004dfbdbafb Mon Sep 17 00:00:00 2001 From: Justin Date: Fri, 22 Nov 2019 11:35:54 -0500 Subject: [PATCH] Update client.py --- disco/gateway/client.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/disco/gateway/client.py b/disco/gateway/client.py index a364617..b778201 100644 --- a/disco/gateway/client.py +++ b/disco/gateway/client.py @@ -73,9 +73,8 @@ class GatewayClient(LoggingClass): self._heartbeat_acknowledged = True # Latency - self._last_send = time.perf_counter() - self._last_ack = time.perf_counter() - self.latency = float('inf') + self._last_heartbeat = 0 + self.latency = -1 def send(self, op, data): self.limiter.check() @@ -96,18 +95,12 @@ class GatewayClient(LoggingClass): self._heartbeat_acknowledged = True self.ws.close(status=4000) return - else: - self._last_send = time.perf_counter() + self._last_heartbeat = time.time() self._send(OPCode.HEARTBEAT, self.seq) self._heartbeat_acknowledged = False 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): obj = GatewayEvent.from_dispatch(self.client, packet) self.log.debug('GatewayClient.handle_dispatch %s', obj.__class__.__name__) @@ -121,7 +114,7 @@ class GatewayClient(LoggingClass): def handle_heartbeat_acknowledge(self, _): self.log.debug('Received HEARTBEAT_ACK') self._heartbeat_acknowledged = True - self.ack() + self.latency = int((time.time() - self._last_heartbeat) * 1000) def handle_reconnect(self, _): self.log.warning('Received RECONNECT request, forcing a fresh reconnect')