From ba084927301b89bac4690bc9cb24af334f0cbac9 Mon Sep 17 00:00:00 2001 From: mamaheux <35638081+mamaheux@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:14:56 -0500 Subject: [PATCH] Signaling server ws ping (#138) * Send a ping every 10 sec * Add missing await. * Bump version --- VERSION | 2 +- .../opentera_webrtc/signaling_server/signaling_server.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 45a1b3f4..781dcb07 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.2 +1.1.3 diff --git a/signaling-server/opentera_webrtc/signaling_server/signaling_server.py b/signaling-server/opentera_webrtc/signaling_server/signaling_server.py index 5932f11a..ad6066be 100755 --- a/signaling-server/opentera_webrtc/signaling_server/signaling_server.py +++ b/signaling-server/opentera_webrtc/signaling_server/signaling_server.py @@ -21,6 +21,7 @@ PROTOCOL_VERSION = 2 DISCONNECT_DELAY_S = 1 INACTIVE_DELAY_S = 5 +PING_INTERVAL_S = 10 @web.middleware @@ -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} @@ -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: