Skip to content

Commit

Permalink
Add test server support
Browse files Browse the repository at this point in the history
  • Loading branch information
olijeffers0n committed Jul 14, 2024
1 parent 08fe1f4 commit 20b3e17
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions rustplus/remote/websocket/ws.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shlex
import base64
import betterproto
from websockets.exceptions import InvalidURI, InvalidHandshake
from websockets.legacy.client import WebSocketClientProtocol
Expand Down Expand Up @@ -69,7 +70,7 @@ async def connect(self) -> bool:
self.logger.warning("WebSocket connection error: %s", err)
return False

if self.use_test_server:
if self.debug:
self.logger.info("Websocket connection established to %s", address)

self.task = asyncio.create_task(
Expand Down Expand Up @@ -103,6 +104,9 @@ async def run(self) -> None:
self.run_proto_event(data, self.server_details)
)

if self.use_test_server:
data = base64.b64decode(data)

app_message = AppMessage()
app_message.parse(data)

Expand Down Expand Up @@ -137,7 +141,12 @@ async def send_message(
self.responses[request.seq] = YieldingEvent()

try:
await self.connection.send(bytes(request))
if self.use_test_server:
await self.connection.send(
base64.b64encode(bytes(request)).decode("utf-8")
)
else:
await self.connection.send(bytes(request))
except Exception as err:
self.logger.warning("WebSocket connection error: %s", err)

Expand Down

0 comments on commit 20b3e17

Please sign in to comment.