Browse Source

fix voice connection issues and upgrade to v8

pull/10210/head
DA-344 1 month ago
parent
commit
2789862ef8
  1. 14
      discord/gateway.py
  2. 2
      discord/voice_state.py

14
discord/gateway.py

@ -212,6 +212,9 @@ class KeepAliveHandler(threading.Thread):
class VoiceKeepAliveHandler(KeepAliveHandler): class VoiceKeepAliveHandler(KeepAliveHandler):
if TYPE_CHECKING:
ws: DiscordVoiceWebSocket
def __init__(self, *args: Any, **kwargs: Any) -> None: def __init__(self, *args: Any, **kwargs: Any) -> None:
name: str = kwargs.pop('name', f'voice-keep-alive-handler:{id(self):#x}') name: str = kwargs.pop('name', f'voice-keep-alive-handler:{id(self):#x}')
super().__init__(*args, name=name, **kwargs) super().__init__(*args, name=name, **kwargs)
@ -223,7 +226,10 @@ class VoiceKeepAliveHandler(KeepAliveHandler):
def get_payload(self) -> Dict[str, Any]: def get_payload(self) -> Dict[str, Any]:
return { return {
'op': self.ws.HEARTBEAT, 'op': self.ws.HEARTBEAT,
'd': int(time.time() * 1000), 'd': {
't': int(time.time() * 1000),
'seq_ack': self.ws.seq_ack,
},
} }
def ack(self) -> None: def ack(self) -> None:
@ -830,6 +836,8 @@ class DiscordVoiceWebSocket:
self._keep_alive: Optional[VoiceKeepAliveHandler] = None self._keep_alive: Optional[VoiceKeepAliveHandler] = None
self._close_code: Optional[int] = None self._close_code: Optional[int] = None
self.secret_key: Optional[List[int]] = None self.secret_key: Optional[List[int]] = None
# defaulting to -1
self.seq_ack: int = -1
if hook: if hook:
self._hook = hook # type: ignore self._hook = hook # type: ignore
@ -876,7 +884,7 @@ class DiscordVoiceWebSocket:
hook: Optional[Callable[..., Coroutine[Any, Any, Any]]] = None, hook: Optional[Callable[..., Coroutine[Any, Any, Any]]] = None,
) -> Self: ) -> Self:
"""Creates a voice websocket for the :class:`VoiceClient`.""" """Creates a voice websocket for the :class:`VoiceClient`."""
gateway = f'wss://{state.endpoint}/?v=4' gateway = f'wss://{state.endpoint}/?v=8'
client = state.voice_client client = state.voice_client
http = client._state.http http = client._state.http
socket = await http.ws_connect(gateway, compress=15) socket = await http.ws_connect(gateway, compress=15)
@ -926,6 +934,7 @@ class DiscordVoiceWebSocket:
'delay': 0, 'delay': 0,
'ssrc': self._connection.ssrc, 'ssrc': self._connection.ssrc,
}, },
'seq': self.seq_ack,
} }
await self.send_as_json(payload) await self.send_as_json(payload)
@ -934,6 +943,7 @@ class DiscordVoiceWebSocket:
_log.debug('Voice websocket frame received: %s', msg) _log.debug('Voice websocket frame received: %s', msg)
op = msg['op'] op = msg['op']
data = msg['d'] # According to Discord this key is always given data = msg['d'] # According to Discord this key is always given
self.seq_ack = msg.get('seq', self.seq_ack) # this key may not be given
if op == self.READY: if op == self.READY:
await self.initial_connection(data) await self.initial_connection(data)

2
discord/voice_state.py

@ -321,7 +321,7 @@ class VoiceConnectionState:
) )
return return
self.endpoint, _, _ = endpoint.rpartition(':') self.endpoint = endpoint
if self.endpoint.startswith('wss://'): if self.endpoint.startswith('wss://'):
# Just in case, strip it off since we're going to add it later # Just in case, strip it off since we're going to add it later
self.endpoint = self.endpoint[6:] self.endpoint = self.endpoint[6:]

Loading…
Cancel
Save