Add vws message hook
This commit is contained in:
parent
cc8a86a4bd
commit
8e08bd6af2
@ -708,12 +708,17 @@ class DiscordVoiceWebSocket:
|
|||||||
CLIENT_CONNECT = 12
|
CLIENT_CONNECT = 12
|
||||||
CLIENT_DISCONNECT = 13
|
CLIENT_DISCONNECT = 13
|
||||||
|
|
||||||
def __init__(self, socket, loop):
|
def __init__(self, socket, loop, *, hook=None):
|
||||||
self.ws = socket
|
self.ws = socket
|
||||||
self.loop = loop
|
self.loop = loop
|
||||||
self._keep_alive = None
|
self._keep_alive = None
|
||||||
self._close_code = None
|
self._close_code = None
|
||||||
self.secret_key = None
|
self.secret_key = None
|
||||||
|
if hook:
|
||||||
|
self._hook = hook
|
||||||
|
|
||||||
|
async def _hook(self, msg):
|
||||||
|
pass
|
||||||
|
|
||||||
async def send_as_json(self, data):
|
async def send_as_json(self, data):
|
||||||
log.debug('Sending voice websocket frame: %s.', data)
|
log.debug('Sending voice websocket frame: %s.', data)
|
||||||
@ -747,12 +752,12 @@ class DiscordVoiceWebSocket:
|
|||||||
await self.send_as_json(payload)
|
await self.send_as_json(payload)
|
||||||
|
|
||||||
@classmethod
|
@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`."""
|
"""Creates a voice websocket for the :class:`VoiceClient`."""
|
||||||
gateway = 'wss://' + client.endpoint + '/?v=4'
|
gateway = 'wss://' + client.endpoint + '/?v=4'
|
||||||
http = client._state.http
|
http = client._state.http
|
||||||
socket = await http.ws_connect(gateway, compress=15)
|
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.gateway = gateway
|
||||||
ws._connection = client
|
ws._connection = client
|
||||||
ws._max_heartbeat_timeout = 60.0
|
ws._max_heartbeat_timeout = 60.0
|
||||||
@ -820,6 +825,8 @@ class DiscordVoiceWebSocket:
|
|||||||
self._keep_alive = VoiceKeepAliveHandler(ws=self, interval=min(interval, 5.0))
|
self._keep_alive = VoiceKeepAliveHandler(ws=self, interval=min(interval, 5.0))
|
||||||
self._keep_alive.start()
|
self._keep_alive.start()
|
||||||
|
|
||||||
|
await self._hook(self, msg)
|
||||||
|
|
||||||
async def initial_connection(self, data):
|
async def initial_connection(self, data):
|
||||||
state = self._connection
|
state = self._connection
|
||||||
state.ssrc = data['ssrc']
|
state.ssrc = data['ssrc']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user