Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribing to Parse Live Query the first time doesn't work #61

Open
mkpazon opened this issue May 17, 2017 · 3 comments
Open

Subscribing to Parse Live Query the first time doesn't work #61

mkpazon opened this issue May 17, 2017 · 3 comments

Comments

@mkpazon
Copy link

mkpazon commented May 17, 2017

In my activity's onResume() I am subscribing to live query

@Override
protected void onResume() {
     SubscriptionHandling<ParseObject> subscriptionHandling = mParseLiveQueryClient.subscribe(messageQuery);
     subscriptionHandling.handleEvents(new SubscriptionHandling.HandleEventsCallback<ParseObject>() {
            @Override
            public void onEvents(ParseQuery<ParseObject> query, SubscriptionHandling.Event event, ParseObject parseMessage) {
                // HANDLING all events
                Timber.d("getMessageHistory -> .onEvents");
                Timber.i(event.name());
            }
        });
}

In my logs I see the following:

V/ParseLiveQueryClient: Socket stateChanged
V/ParseLiveQueryClient: Socket stateChanged
V/ParseLiveQueryClient: Socket opened
V/ParseLiveQueryClient: Socket onMessage {"op":"connected","clientId":88}
V/ParseLiveQueryClient: Connected, sending pending subscription

No events are being caught.

When I switch to another application and go back then my onResume() is triggered again re-registering to live query. I get the following logs: (Notice that this now has the "subscribed" part)

V/ParseLiveQueryClient: Socket stateChanged
V/ParseLiveQueryClient: Socket stateChanged
V/ParseLiveQueryClient: Socket opened
V/ParseLiveQueryClient: Socket onMessage {"op":"connected","clientId":91}
V/ParseLiveQueryClient: Connected, sending pending subscription
V/ParseLiveQueryClient: Socket onMessage {"op":"subscribed","clientId":91,"requestId":1}

This now is able to receive all the events.

Howcome the first registration doesn't work while the 2nd one works?

@mkpazon
Copy link
Author

mkpazon commented May 17, 2017

One ugly work around I came up with is to disconnect and reconnect:

 mParseLiveQueryClient.registerListener(new ParseLiveQueryClientCallbacks() {
            @Override
            public void onLiveQueryClientConnected(ParseLiveQueryClient client) {
                Timber.d("[liveQuery] -> .onLiveQueryClientConnected");
                if (counter == 0) {
                    client.disconnect();
                    counter++;
                    startWebsocketConnection();
                }
            }
             ...
        });

@mmimeault
Copy link
Contributor

Which version of liveQuery are you using? Of course, it's not normal that you need 2 subscriptions to make it work.
It should be working the first time.

@mkpazon
Copy link
Author

mkpazon commented May 24, 2017

I am using 1.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants