|
|
@ -71,7 +71,7 @@ class KeepAliveHandler(threading.Thread): |
|
|
|
while not self._stop_ev.wait(self.interval): |
|
|
|
if self._last_ack + 2 * self.interval < time.time(): |
|
|
|
log.warn("We have stopped responding to the gateway.") |
|
|
|
coro = self.ws.close(1001) |
|
|
|
coro = self.ws.close(1006) |
|
|
|
f = compat.run_coroutine_threadsafe(coro, loop=self.ws.loop) |
|
|
|
|
|
|
|
try: |
|
|
@ -191,13 +191,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
|
This is for internal use only. |
|
|
|
""" |
|
|
|
gateway = yield from client.http.get_gateway() |
|
|
|
try: |
|
|
|
ws = yield from asyncio.wait_for( |
|
|
|
websockets.connect(gateway, loop=client.loop, klass=cls), |
|
|
|
timeout=60, loop=client.loop) |
|
|
|
except asyncio.TimeoutError: |
|
|
|
log.warn('timed out waiting for client connect') |
|
|
|
return (yield from cls.from_client(client, resume=resume)) |
|
|
|
ws = yield from websockets.connect(gateway, loop=client.loop, klass=cls) |
|
|
|
|
|
|
|
# dynamically add attributes needed |
|
|
|
ws.token = client.http.token |
|
|
@ -212,12 +206,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
|
log.info('Created websocket connected to {}'.format(gateway)) |
|
|
|
|
|
|
|
# poll event for OP Hello |
|
|
|
try: |
|
|
|
yield from asyncio.wait_for(ws.poll_event(), timeout=60, loop=client.loop) |
|
|
|
except asyncio.TimeoutError: |
|
|
|
log.warn("timed out waiting for client HELLO") |
|
|
|
yield from ws.close(1001) |
|
|
|
return (yield from cls.from_client(client, resume=resume)) |
|
|
|
yield from ws.poll_event() |
|
|
|
|
|
|
|
if not resume: |
|
|
|
yield from ws.identify() |
|
|
@ -230,7 +219,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
|
yield from ws.ensure_open() |
|
|
|
except websockets.exceptions.ConnectionClosed: |
|
|
|
# ws got closed so let's just do a regular IDENTIFY connect. |
|
|
|
log.warn('RESUME failure.') |
|
|
|
log.info('RESUME failure.') |
|
|
|
return (yield from cls.from_client(client)) |
|
|
|
else: |
|
|
|
return ws |
|
|
@ -536,7 +525,6 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
|
HEARTBEAT = 3 |
|
|
|
SESSION_DESCRIPTION = 4 |
|
|
|
SPEAKING = 5 |
|
|
|
HELLO = 8 |
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs): |
|
|
|
super().__init__(*args, **kwargs) |
|
|
@ -552,14 +540,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
|
def from_client(cls, client): |
|
|
|
"""Creates a voice websocket for the :class:`VoiceClient`.""" |
|
|
|
gateway = 'wss://' + client.endpoint |
|
|
|
try: |
|
|
|
ws = yield from asyncio.wait_for( |
|
|
|
websockets.connect(gateway, loop=client.loop, klass=cls), |
|
|
|
timeout=60, loop=client.loop) |
|
|
|
except asyncio.TimeoutError: |
|
|
|
log.warn("timed out waiting for voice client connect") |
|
|
|
return (yield from cls.from_client(client)) |
|
|
|
|
|
|
|
ws = yield from websockets.connect(gateway, loop=client.loop, klass=cls) |
|
|
|
ws.gateway = gateway |
|
|
|
ws._connection = client |
|
|
|
|
|
|
@ -574,16 +555,6 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol): |
|
|
|
} |
|
|
|
|
|
|
|
yield from ws.send_as_json(identify) |
|
|
|
|
|
|
|
try: |
|
|
|
# Wait until we have processed READY and keep alive is running |
|
|
|
while not ws._keep_alive: |
|
|
|
yield from asyncio.wait_for(ws.poll_event(), timeout=60, loop=client.loop) |
|
|
|
except asyncio.TimeoutError: |
|
|
|
log.warn("timed out waiting for voice client READY") |
|
|
|
yield from ws.close(1001) |
|
|
|
return (yield from cls.from_client(client)) |
|
|
|
|
|
|
|
return ws |
|
|
|
|
|
|
|
@asyncio.coroutine |
|
|
|