@ -64,10 +64,11 @@ class KeepAliveHandler(threading.Thread):
self . _stop_ev = threading . Event ( )
self . _stop_ev = threading . Event ( )
self . _last_ack = time . time ( )
self . _last_ack = time . time ( )
self . _last_send = time . time ( )
self . _last_send = time . time ( )
self . heartbeat_timeout = ws . _max_heartbeat_timeout
def run ( self ) :
def run ( self ) :
while not self . _stop_ev . wait ( self . interval ) :
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 )
log . warn ( " Shard ID %s has stopped responding to the gateway. Closing and restarting. " % self . shard_id )
coro = self . ws . close ( 1006 )
coro = self . ws . close ( 1006 )
f = compat . run_coroutine_threadsafe ( coro , loop = self . ws . loop )
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 . shard_count = client . _connection . shard_count
ws . session_id = session
ws . session_id = session
ws . sequence = sequence
ws . sequence = sequence
ws . _max_heartbeat_timeout = client . _connection . heartbeat_timeout
client . _connection . _update_references ( ws )
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 = yield from websockets . connect ( gateway , loop = client . loop , klass = cls )
ws . gateway = gateway
ws . gateway = gateway
ws . _connection = client
ws . _connection = client
ws . _max_heartbeat_timeout = 60.0
if resume :
if resume :
yield from ws . resume ( )
yield from ws . resume ( )