Add and remove some of the on_socket_* events.

on_socket_raw_receive and on_socket_raw_send were added back in an odd
way. The rest of them such as on_socket_closed, on_socket_opened, and
on_socket_receive were removed.
This commit is contained in:
Rapptz
2016-01-25 01:53:35 -05:00
parent 4d816c4ef3
commit 8b1854e759
3 changed files with 32 additions and 49 deletions

View File

@ -147,6 +147,11 @@ class Client:
filename = hashlib.md5(email.encode('utf-8')).hexdigest()
return os.path.join(tempfile.gettempdir(), 'discord_py', filename)
@asyncio.coroutine
def _send_ws(self, data):
self.dispatch('socket_raw_send', data)
yield from self.ws.send(data)
@asyncio.coroutine
def _login_via_cache(self, email, password):
try:
@ -282,7 +287,7 @@ class Client:
msg = 'Keeping websocket alive with timestamp {}'
log.debug(msg.format(payload['d']))
yield from self.ws.send(utils.to_json(payload))
yield from self._send_ws(utils.to_json(payload))
yield from asyncio.sleep(interval)
except asyncio.CancelledError:
pass
@ -302,6 +307,8 @@ class Client:
@asyncio.coroutine
def received_message(self, msg):
self.dispatch('socket_raw_receive', msg)
if isinstance(msg, bytes):
msg = zlib.decompress(msg, 15, 10490000) # This is 10 MiB
msg = msg.decode('utf-8')
@ -386,7 +393,7 @@ class Client:
}
}
yield from self.ws.send(utils.to_json(payload))
yield from self._send_ws(utils.to_json(payload))
log.info('sent the initial payload to create the websocket')
@asyncio.coroutine
@ -415,7 +422,7 @@ class Client:
}
log.info('sending reconnection frame to websocket {}'.format(payload))
yield from self.ws.send(utils.to_json(payload))
yield from self._send_ws(utils.to_json(payload))
# login state management
@ -1462,7 +1469,7 @@ class Client:
sent = utils.to_json(payload)
log.debug('Sending "{}" to change status'.format(sent))
yield from self.ws.send(sent)
yield from self._send_ws(sent)
# Channel management
@ -2431,7 +2438,7 @@ class Client:
}
}
yield from self.ws.send(utils.to_json(payload))
yield from self._send_ws(utils.to_json(payload))
yield from asyncio.wait_for(self._session_id_found.wait(), timeout=5.0, loop=self.loop)
yield from asyncio.wait_for(self._voice_data_found.wait(), timeout=5.0, loop=self.loop)