Description
I have created a Web App use the Parse backend which utilises Parse's LiveQuery (Websockets).
Whilst testing on mobile devices, I have noticed that after a long(ish) sleep the LiveQuery events don't seem to get through. Best as I can tell/understand, the browser is closing (?) the websocket.
Behind the scenes, I know the Parse JS SDK implements an exponential backoff automatic reconnect.
Is there a way to instantly auto connect on the browser window getting focus?
I tried a quick hack in the JS SDK as follows in the LiveQuery 'open' function
if (firstTime) {
$(window).on('focus', function () {
console.log("Window got focus");
this.attempts = 0;
console.log(_this4.state)
if (_this4.state !== CLIENT_STATE.CONNECTED)
_this4._handleReconnect();
});
firstTime = false;
}
However, this does not seem to work (at least not consistently). If I remove the check on the CONNECTED
status, then it seems to work but then I end up with multiple sockets open (I know as I have a toast popup that is activated on live updates -- without the CONNECT
check I get two popups instead of one). So, does that suggest that the Parse SDK is not aware the connection is broken? How I can I force a check?