aboutsummaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
Diffstat (limited to 'discord')
-rw-r--r--discord/gateway.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/discord/gateway.py b/discord/gateway.py
index afac2c03..077d16d2 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -708,13 +708,18 @@ class DiscordVoiceWebSocket:
CLIENT_CONNECT = 12
CLIENT_DISCONNECT = 13
- def __init__(self, socket, loop):
+ def __init__(self, socket, loop, *, hook=None):
self.ws = socket
self.loop = loop
self._keep_alive = None
self._close_code = None
self.secret_key = None
+ if hook:
+ self._hook = hook
+ async def _hook(self, msg):
+ pass
+
async def send_as_json(self, data):
log.debug('Sending voice websocket frame: %s.', data)
await self.ws.send_str(utils.to_json(data))
@@ -747,12 +752,12 @@ class DiscordVoiceWebSocket:
await self.send_as_json(payload)
@classmethod
- async def from_client(cls, client, *, resume=False):
+ async def from_client(cls, client, *, resume=False, hook=None):
"""Creates a voice websocket for the :class:`VoiceClient`."""
gateway = 'wss://' + client.endpoint + '/?v=4'
http = client._state.http
socket = await http.ws_connect(gateway, compress=15)
- ws = cls(socket, loop=client.loop)
+ ws = cls(socket, loop=client.loop, hook=hook)
ws.gateway = gateway
ws._connection = client
ws._max_heartbeat_timeout = 60.0
@@ -819,6 +824,8 @@ class DiscordVoiceWebSocket:
interval = data['heartbeat_interval'] / 1000.0
self._keep_alive = VoiceKeepAliveHandler(ws=self, interval=min(interval, 5.0))
self._keep_alive.start()
+
+ await self._hook(self, msg)
async def initial_connection(self, data):
state = self._connection