Check if websocket is connected as part of pushAvailable() check

This commit is contained in:
nathan 2022-11-11 08:45:55 -07:00
parent 9188b04256
commit bd584e468c

View File

@ -98,6 +98,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
const check_interval = 30000; // 30 sec const check_interval = 30000; // 30 sec
const max_ping_response_time = 1000; const max_ping_response_time = 1000;
let reconnect_time = min_reconnect_time; let reconnect_time = min_reconnect_time;
let websocket = null;
/** /**
* Open websocket to push server (and keeps it open) * Open websocket to push server (and keeps it open)
@ -128,7 +129,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
}.bind(this), max_ping_response_time); }.bind(this), max_ping_response_time);
}.bind(this); }.bind(this);
this.websocket = new WebSocket(url); websocket = this.websocket = new WebSocket(url);
this.websocket.onopen = (e) => this.websocket.onopen = (e) =>
{ {
check_timer = window.setTimeout(check, check_interval); check_timer = window.setTimeout(check, check_interval);
@ -446,7 +447,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd)
*/ */
pushAvailable: function() pushAvailable: function()
{ {
return reconnect_time === min_reconnect_time; return websocket !== null && websocket.readyState == websocket.OPEN && reconnect_time === min_reconnect_time;
}, },
/** The constructor of the egw_json_request class. /** The constructor of the egw_json_request class.