Fix voice websocket connections
This commit is contained in:
parent
988505a97f
commit
058a1e608b
@ -503,7 +503,7 @@ class DiscordWebSocket:
|
||||
raise msg.data
|
||||
elif msg.type in (aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSE):
|
||||
log.debug('Received %s', msg)
|
||||
raise WebSocketClosure('Unexpected WebSocket closure.')
|
||||
raise WebSocketClosure
|
||||
except WebSocketClosure as e:
|
||||
if self._can_handle_close():
|
||||
log.info('Websocket closed with %s, attempting a reconnect.', self.socket.close_code)
|
||||
@ -638,8 +638,9 @@ class DiscordVoiceWebSocket:
|
||||
CLIENT_CONNECT = 12
|
||||
CLIENT_DISCONNECT = 13
|
||||
|
||||
def __init__(self, socket):
|
||||
def __init__(self, socket, loop):
|
||||
self.ws = socket
|
||||
self.loop = loop
|
||||
self._keep_alive = None
|
||||
|
||||
async def send_as_json(self, data):
|
||||
@ -676,8 +677,8 @@ class DiscordVoiceWebSocket:
|
||||
"""Creates a voice websocket for the :class:`VoiceClient`."""
|
||||
gateway = 'wss://' + client.endpoint + '/?v=4'
|
||||
http = client._state.http
|
||||
socket = await http.ws_connect(gateway)
|
||||
ws = cls(socket)
|
||||
socket = await http.ws_connect(gateway, compress=15)
|
||||
ws = cls(socket, loop=client.loop)
|
||||
ws.gateway = gateway
|
||||
ws._connection = client
|
||||
ws._max_heartbeat_timeout = 60.0
|
||||
|
@ -85,6 +85,10 @@ class MaybeUnlock:
|
||||
if self._unlock:
|
||||
self.lock.release()
|
||||
|
||||
# For some reason, the Discord voice websocket expects this header to be
|
||||
# completely lowercase while aiohttp respects spec and does it as case-insensitive
|
||||
aiohttp.hdrs.WEBSOCKET = 'websocket'
|
||||
|
||||
class HTTPClient:
|
||||
"""Represents an HTTP client sending HTTP requests to the Discord API."""
|
||||
|
||||
@ -111,13 +115,17 @@ class HTTPClient:
|
||||
if self.__session.closed:
|
||||
self.__session = aiohttp.ClientSession(connector=self.connector)
|
||||
|
||||
async def ws_connect(self, url):
|
||||
async def ws_connect(self, url, *, compress=0):
|
||||
kwargs = {
|
||||
'proxy_auth': self.proxy_auth,
|
||||
'proxy': self.proxy,
|
||||
'max_msg_size': 0,
|
||||
'timeout': 30.0,
|
||||
'autoclose': False,
|
||||
'headers': {
|
||||
'User-Agent': self.user_agent,
|
||||
},
|
||||
'compress': compress
|
||||
}
|
||||
|
||||
return await self.__session.ws_connect(url, **kwargs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user