Skip to content

Commit a89cb09

Browse files
authored
Merge pull request #12 from hmate9/feat/ws-client-pong-response
feat(ws-client): respond with pong to ping messages
2 parents 7b7c296 + 0af5fa8 commit a89cb09

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lighter/ws_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from websockets.client import connect as connect_async
44
from lighter.configuration import Configuration
55

6-
76
class WsClient:
87
def __init__(
98
self,
@@ -51,6 +50,9 @@ def on_message(self, ws, message):
5150
self.handle_subscribed_account(message)
5251
elif message_type == "update/account_all":
5352
self.handle_update_account(message)
53+
elif message_type == "ping":
54+
# Respond to ping with pong
55+
ws.send(json.dumps({"type": "pong"}))
5456
else:
5557
self.handle_unhandled_message(message)
5658

@@ -60,6 +62,9 @@ async def on_message_async(self, ws, message):
6062

6163
if message_type == "connected":
6264
await self.handle_connected_async(ws)
65+
elif message_type == "ping":
66+
# Respond to ping with pong
67+
await ws.send(json.dumps({"type": "pong"}))
6368
else:
6469
self.on_message(ws, message)
6570

0 commit comments

Comments
 (0)