Skip to content

Commit

Permalink
Signaling server ws ping (#138)
Browse files Browse the repository at this point in the history
* Send a ping every 10 sec

* Add missing await.

* Bump version
  • Loading branch information
mamaheux authored Jan 16, 2024
1 parent f760ae2 commit ba08492
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.1.3
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
PROTOCOL_VERSION = 2
DISCONNECT_DELAY_S = 1
INACTIVE_DELAY_S = 5
PING_INTERVAL_S = 10


@web.middleware
Expand Down Expand Up @@ -58,6 +59,12 @@ async def disconnect_inactive_user(id):
await web_socket_client_manager.close(id)


async def web_socket_ping_task(ws):
while not ws.closed:
await asyncio.sleep(PING_INTERVAL_S)
await ws.ping()


def event_to_message(event, data=None):
if data is None:
message = {'event': event}
Expand All @@ -74,6 +81,7 @@ async def web_socket_handler(request):
id = await web_socket_client_manager.add_ws(ws)
logger.info('connect %s', id)
asyncio.create_task(disconnect_inactive_user(id))
asyncio.create_task(web_socket_ping_task(ws))

async for msg in ws:
if msg.type == WSMsgType.TEXT:
Expand Down

0 comments on commit ba08492

Please sign in to comment.