Skip to content

LiveQuery socket not reconnecting on resume from sleep in mobile #585

Closed
@dpatel20

Description

@dpatel20

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions