aboutsummaryrefslogtreecommitdiff
path: root/discord/gateway.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-08-08 21:12:04 -0400
committerRapptz <[email protected]>2017-08-08 21:12:04 -0400
commitde65f7309bc8f8c931f29dcd76ebd9e8b0ee547b (patch)
tree31d5e4e151f6757c677aa854cfa70f644635df00 /discord/gateway.py
parentAdd DiscordWebSocket.latency to measure discord heartbeat latency. (diff)
downloaddiscord.py-de65f7309bc8f8c931f29dcd76ebd9e8b0ee547b.tar.xz
discord.py-de65f7309bc8f8c931f29dcd76ebd9e8b0ee547b.zip
Add heartbeat_timeout to the Client options.
This setting configures how long before a timeout event is emitted internally and disconnects the websocket. Since some users were experiencing issues with the gateway not responding, this should help mitigate the issue for those with poor PCs.
Diffstat (limited to 'discord/gateway.py')
-rw-r--r--discord/gateway.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/discord/gateway.py b/discord/gateway.py
index d5ddb9eb..50104034 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -64,10 +64,11 @@ class KeepAliveHandler(threading.Thread):
self._stop_ev = threading.Event()
self._last_ack = time.time()
self._last_send = time.time()
+ self.heartbeat_timeout = ws._max_heartbeat_timeout
def run(self):
while not self._stop_ev.wait(self.interval):
- if self._last_ack + 2 * self.interval < time.time():
+ if self._last_ack + self.heartbeat_timeout < time.time():
log.warn("Shard ID %s has stopped responding to the gateway. Closing and restarting." % self.shard_id)
coro = self.ws.close(1006)
f = compat.run_coroutine_threadsafe(coro, loop=self.ws.loop)
@@ -205,6 +206,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
ws.shard_count = client._connection.shard_count
ws.session_id = session
ws.sequence = sequence
+ ws._max_heartbeat_timeout = client._connection.heartbeat_timeout
client._connection._update_references(ws)
@@ -590,6 +592,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
ws = yield from websockets.connect(gateway, loop=client.loop, klass=cls)
ws.gateway = gateway
ws._connection = client
+ ws._max_heartbeat_timeout = 60.0
if resume:
yield from ws.resume()