From 9f2b715d9ffbecbfeec1799f7137e2af6c34f013 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Sat, 13 Jul 2019 21:40:48 +0200 Subject: [PATCH] exponential backoff --- htdocs/openwebrx.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js index e004ae4..6917541 100644 --- a/htdocs/openwebrx.js +++ b/htdocs/openwebrx.js @@ -1472,6 +1472,7 @@ function on_ws_opened() { ws.send("SERVER DE CLIENT client=openwebrx.js type=receiver"); divlog("WebSocket opened to "+ws_url); + reconnect_timeout = false; } var was_error=0; @@ -1852,6 +1853,8 @@ function audio_init() } +var reconnect_timeout = false; + function on_ws_closed() { try @@ -1860,9 +1863,16 @@ function on_ws_closed() } catch (dont_care) {} audio_initialized = 0; - divlog("WebSocket has closed unexpectedly. Attempting to reconnect in 5 seconds...", 1); + if (reconnect_timeout) { + // max value: roundabout 8 and a half minutes + reconnect_timeout = Math.min(reconnect_timeout * 2, 512000); + } else { + // initial value: 1s + reconnect_timeout = 1000; + } + divlog("WebSocket has closed unexpectedly. Attempting to reconnect in " + reconnect_timeout / 1000 + " seconds...", 1); - setTimeout(open_websocket, 5000); + setTimeout(open_websocket, reconnect_timeout); } function on_ws_error(event)