File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,7 @@ async def start(self):
75
75
uri = '%s?ticket=%s' % (connection ['endpoint' ], urllib .parse .quote_plus (connection ['ticket' ]))
76
76
async with websockets .connect (uri ) as websocket :
77
77
self .websocket = websocket
78
+ keepalive_task = asyncio .create_task (self .keepalive (websocket ))
78
79
async for raw_message in websocket :
79
80
json_message = json .loads (raw_message )
80
81
asyncio .create_task (self .background_task (json_message ))
@@ -92,6 +93,14 @@ async def start(self):
92
93
finally :
93
94
pass
94
95
96
+ async def keepalive (self , ws , ping_interval = 1 ):
97
+ while True :
98
+ await asyncio .sleep (ping_interval )
99
+ try :
100
+ await ws .ping ()
101
+ except websockets .exceptions .ConnectionClosed :
102
+ break
103
+
95
104
async def background_task (self , json_message ):
96
105
try :
97
106
route_result = await self .route_message (json_message )
You can’t perform that action at this time.
0 commit comments