gateway.websocket: fix etf

This commit is contained in:
Luna 2019-04-25 22:26:45 -03:00
parent b6da5ad9d3
commit 9f50721243
1 changed files with 8 additions and 1 deletions

View File

@ -227,6 +227,7 @@ class GatewayWebsocket:
payload.get('s'), payload.get('s'),
payload.get('t')) payload.get('t'))
# treat encoded as bytes
if not isinstance(encoded, bytes): if not isinstance(encoded, bytes):
encoded = encoded.encode() encoded = encoded.encode()
@ -237,7 +238,13 @@ class GatewayWebsocket:
# should do all? # should do all?
await self.ws.send(zlib.compress(encoded)) await self.ws.send(zlib.compress(encoded))
else: else:
try:
# assume encoded is string, json based, decoding it
# should give reasonable messages down the websocket
await self.ws.send(encoded.decode()) await self.ws.send(encoded.decode())
except UnicodeDecodeError:
# in here, encoded is ETF, its bytes(), so we send it raw
await self.ws.send(encoded)
async def send_op(self, op_code: int, data: Any): async def send_op(self, op_code: int, data: Any):
"""Send a packet but just the OP code information is filled in.""" """Send a packet but just the OP code information is filled in."""