Add support for resume_gateway_url

This commit is contained in:
Rapptz
2022-08-05 08:17:52 -04:00
parent a36d6daec7
commit 7da2048d1a
4 changed files with 33 additions and 4 deletions

View File

@ -682,6 +682,8 @@ class Client:
_log.info('Got a request to %s the websocket.', e.op)
self.dispatch('disconnect')
ws_params.update(sequence=self.ws.sequence, resume=e.resume, session=self.ws.session_id)
if e.resume:
ws_params['gateway'] = self.ws.gateway
continue
except (
OSError,
@ -705,7 +707,13 @@ class Client:
# If we get connection reset by peer then try to RESUME
if isinstance(exc, OSError) and exc.errno in (54, 10054):
ws_params.update(sequence=self.ws.sequence, initial=False, resume=True, session=self.ws.session_id)
ws_params.update(
sequence=self.ws.sequence,
gateway=self.ws.gateway,
initial=False,
resume=True,
session=self.ws.session_id,
)
continue
# We should only get this when an unhandled close code happens,
@ -725,7 +733,12 @@ class Client:
# Always try to RESUME the connection
# If the connection is not RESUME-able then the gateway will invalidate the session.
# This is apparently what the official Discord client does.
ws_params.update(sequence=self.ws.sequence, resume=True, session=self.ws.session_id)
ws_params.update(
sequence=self.ws.sequence,
gateway=self.ws.gateway,
resume=True,
session=self.ws.session_id,
)
async def close(self) -> None:
"""|coro|