|
|
@ -321,7 +321,7 @@ class VoiceConnectionState: |
|
|
|
) |
|
|
|
return |
|
|
|
|
|
|
|
self.endpoint, _, _ = endpoint.rpartition(':') |
|
|
|
self.endpoint = endpoint |
|
|
|
if self.endpoint.startswith('wss://'): |
|
|
|
# Just in case, strip it off since we're going to add it later |
|
|
|
self.endpoint = self.endpoint[6:] |
|
|
@ -574,7 +574,10 @@ class VoiceConnectionState: |
|
|
|
self._disconnected.clear() |
|
|
|
|
|
|
|
async def _connect_websocket(self, resume: bool) -> DiscordVoiceWebSocket: |
|
|
|
ws = await DiscordVoiceWebSocket.from_connection_state(self, resume=resume, hook=self.hook) |
|
|
|
seq_ack = -1 |
|
|
|
if self.ws is not MISSING: |
|
|
|
seq_ack = self.ws.seq_ack |
|
|
|
ws = await DiscordVoiceWebSocket.from_connection_state(self, resume=resume, hook=self.hook, seq_ack=seq_ack) |
|
|
|
self.state = ConnectionFlowState.websocket_connected |
|
|
|
return ws |
|
|
|
|
|
|
@ -603,15 +606,17 @@ class VoiceConnectionState: |
|
|
|
# The following close codes are undocumented so I will document them here. |
|
|
|
# 1000 - normal closure (obviously) |
|
|
|
# 4014 - we were externally disconnected (voice channel deleted, we were moved, etc) |
|
|
|
# 4015 - voice server has crashed |
|
|
|
if exc.code in (1000, 4015): |
|
|
|
# 4015 - voice server has crashed, we should resume |
|
|
|
# 4021 - rate limited, we should not reconnect |
|
|
|
# 4022 - call terminated, similar to 4014 |
|
|
|
if exc.code == 1000: |
|
|
|
# Don't call disconnect a second time if the websocket closed from a disconnect call |
|
|
|
if not self._expecting_disconnect: |
|
|
|
_log.info('Disconnecting from voice normally, close code %d.', exc.code) |
|
|
|
await self.disconnect() |
|
|
|
break |
|
|
|
|
|
|
|
if exc.code == 4014: |
|
|
|
if exc.code in (4014, 4022): |
|
|
|
# We were disconnected by discord |
|
|
|
# This condition is a race between the main ws event and the voice ws closing |
|
|
|
if self._disconnected.is_set(): |
|
|
@ -631,6 +636,31 @@ class VoiceConnectionState: |
|
|
|
else: |
|
|
|
continue |
|
|
|
|
|
|
|
if exc.code == 4021: |
|
|
|
_log.warning('We are being ratelimited while trying to connect to voice. Disconnecting...') |
|
|
|
if self.state is not ConnectionFlowState.disconnected: |
|
|
|
await self.disconnect() |
|
|
|
break |
|
|
|
|
|
|
|
if exc.code == 4015: |
|
|
|
_log.info('Disconnected from voice, attempting a resume...') |
|
|
|
try: |
|
|
|
await self._connect( |
|
|
|
reconnect=reconnect, |
|
|
|
timeout=self.timeout, |
|
|
|
self_deaf=(self.self_voice_state or self).self_deaf, |
|
|
|
self_mute=(self.self_voice_state or self).self_mute, |
|
|
|
resume=True, |
|
|
|
) |
|
|
|
except asyncio.TimeoutError: |
|
|
|
_log.info('Could not resume the voice connection... Disconnecting...') |
|
|
|
if self.state is not ConnectionFlowState.disconnected: |
|
|
|
await self.disconnect() |
|
|
|
break |
|
|
|
else: |
|
|
|
_log.info('Successfully resumed voice connection') |
|
|
|
continue |
|
|
|
|
|
|
|
_log.debug('Not handling close code %s (%s)', exc.code, exc.reason or 'no reason') |
|
|
|
|
|
|
|
if not reconnect: |
|
|
|