|
17 | 17 | from time import perf_counter |
18 | 18 | from typing import Any, Dict, List, Optional, Tuple, Union |
19 | 19 |
|
20 | | -from aiohttp import WSMessage |
21 | | -from aiohttp.http import WS_CLOSED_MESSAGE |
| 20 | +from aiohttp import WSMessage, WSMsgType |
| 21 | +from aiohttp.http import WS_CLOSED_MESSAGE, WS_CLOSING_MESSAGE |
22 | 22 |
|
23 | 23 | from ..base import get_logger |
24 | 24 | from ..enums import InteractionType, OptionType |
@@ -199,7 +199,7 @@ async def _establish_connection( |
199 | 199 |
|
200 | 200 | if stream is None: |
201 | 201 | continue |
202 | | - if self._client is None or stream == WS_CLOSED_MESSAGE: |
| 202 | + if self._client is None or stream == WS_CLOSED_MESSAGE or stream == WSMsgType.CLOSE: |
203 | 203 | await self._establish_connection() |
204 | 204 | break |
205 | 205 |
|
@@ -537,8 +537,18 @@ async def __receive_packet_stream(self) -> Optional[Dict[str, Any]]: |
537 | 537 | """ |
538 | 538 |
|
539 | 539 | packet: WSMessage = await self._client.receive() |
540 | | - if packet == WS_CLOSED_MESSAGE: |
| 540 | + |
| 541 | + if packet == WSMsgType.CLOSE: |
| 542 | + await self._client.close() |
| 543 | + return packet |
| 544 | + |
| 545 | + elif packet == WS_CLOSED_MESSAGE: |
541 | 546 | return packet |
| 547 | + |
| 548 | + elif packet == WS_CLOSING_MESSAGE: |
| 549 | + await self._client.close() |
| 550 | + return WS_CLOSED_MESSAGE |
| 551 | + |
542 | 552 | return loads(packet.data) if packet and isinstance(packet.data, str) else None |
543 | 553 |
|
544 | 554 | async def _send_packet(self, data: Dict[str, Any]) -> None: |
|
0 commit comments