From 5302675aac461fee81f71dafc58ece8db2c7a204 Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 7 Nov 2022 21:31:04 +0100 Subject: [PATCH] new method egw.pushAvailable() : bool to check availability of push-server on client-side --- api/js/jsapi/egw_json.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/api/js/jsapi/egw_json.js b/api/js/jsapi/egw_json.js index 8e9463ebe2..1db3b6795b 100644 --- a/api/js/jsapi/egw_json.js +++ b/api/js/jsapi/egw_json.js @@ -93,6 +93,12 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) }; } + const min_reconnect_time = 1000; + const max_reconnect_time = 300000; + const check_interval = 30000; // 30 sec + const max_ping_response_time = 1000; + let reconnect_time = min_reconnect_time; + /** * Open websocket to push server (and keeps it open) * @@ -104,11 +110,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) */ json_request.prototype.openWebSocket = function(url, tokens, account_id, error, reconnect) { - const min_reconnect_time = 1000; - const max_reconnect_time = 300000; - const check_interval = 30000; // 30 sec - const max_ping_response_time = 1000; - let reconnect_time = reconnect || min_reconnect_time; + reconnect_time = reconnect || min_reconnect_time; let check_timer; let check = function() { @@ -429,7 +431,17 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) } }; - var json = { + var json = + { + /** + * Check if there is a *working* connection to a push server + * + * @return {boolean} + */ + pushAvailable: function() + { + return reconnect_time === min_reconnect_time; + }, /** The constructor of the egw_json_request class. *