Skip to content

Commit 75aa17c

Browse files
committed
fix voice issues
1 parent 8e97cb5 commit 75aa17c

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ These changes are available on the `master` branch, but have not yet been releas
119119
([#2781](https://github.com/Pycord-Development/pycord/pull/2781))
120120
- Fixed `VoiceClient` crashing randomly while receiving audio
121121
([#2800](https://github.com/Pycord-Development/pycord/pull/2800))
122+
- Fixed `VoiceClient.connect` failing to do initial connection.
123+
([#](https://github.com/Pycord-Development/pycord/pull/))
122124

123125
### Changed
124126

discord/gateway.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import traceback
3636
import zlib
3737
from collections import deque, namedtuple
38+
from typing import TYPE_CHECKING
3839

3940
import aiohttp
4041

@@ -208,6 +209,9 @@ def ack(self):
208209

209210

210211
class VoiceKeepAliveHandler(KeepAliveHandler):
212+
if TYPE_CHECKING:
213+
ws: DiscordVoiceWebSocket
214+
211215
def __init__(self, *args, **kwargs):
212216
super().__init__(*args, **kwargs)
213217
self.recent_ack_latencies = deque(maxlen=20)
@@ -216,7 +220,7 @@ def __init__(self, *args, **kwargs):
216220
self.behind_msg = "High socket latency, shard ID %s heartbeat is %.1fs behind"
217221

218222
def get_payload(self):
219-
return {"op": self.ws.HEARTBEAT, "d": int(time.time() * 1000)}
223+
return {"op": self.ws.HEARTBEAT, "d": {"t": int(time.time() * 1000), "seq_ack": self.ws.seq_ack}}
220224

221225
def ack(self):
222226
ack_time = time.perf_counter()
@@ -784,6 +788,7 @@ def __init__(self, socket, loop, *, hook=None):
784788
self._close_code = None
785789
self.secret_key = None
786790
self.ssrc_map = {}
791+
self.seq_ack: int = -1
787792
if hook:
788793
self._hook = hook
789794

@@ -824,7 +829,7 @@ async def identify(self):
824829
@classmethod
825830
async def from_client(cls, client, *, resume=False, hook=None):
826831
"""Creates a voice websocket for the :class:`VoiceClient`."""
827-
gateway = f"wss://{client.endpoint}/?v=4"
832+
gateway = f"wss://{client.endpoint}/?v=8"
828833
http = client._state.http
829834
socket = await http.ws_connect(gateway, compress=15)
830835
ws = cls(socket, loop=client.loop, hook=hook)
@@ -860,14 +865,22 @@ async def client_connect(self):
860865
await self.send_as_json(payload)
861866

862867
async def speak(self, state=SpeakingState.voice):
863-
payload = {"op": self.SPEAKING, "d": {"speaking": int(state), "delay": 0}}
868+
payload = {
869+
"op": self.SPEAKING,
870+
"d": {
871+
"speaking": int(state),
872+
"delay": 0,
873+
},
874+
"seq": self.seq_ack,
875+
}
864876

865877
await self.send_as_json(payload)
866878

867879
async def received_message(self, msg):
868880
_log.debug("Voice websocket frame received: %s", msg)
869881
op = msg["op"]
870882
data = msg.get("d")
883+
self.seq_ack = data.get("seq", self.seq_ack)
871884

872885
if op == self.READY:
873886
await self.initial_connection(data)

discord/voice_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ async def on_voice_server_update(self, data: VoiceServerUpdatePayload) -> None:
325325
)
326326
return
327327

328-
self.endpoint, _, _ = endpoint.rpartition(":")
328+
self.endpoint = endpoint
329329
if self.endpoint.startswith("wss://"):
330330
# Just in case, strip it off since we're going to add it later
331331
self.endpoint = self.endpoint[6:]

0 commit comments

Comments
 (0)