delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

Subscription is lost #107

Closed PavelEgorov1 closed 7 years ago

PavelEgorov1 commented 8 years ago

I have a problem with subscriptions. Server has to send me some JSON objects by logic of subscription. And sometimes, it doesn't send me anything(usually sends). I can't understand why this happens. Maybe cause it appears when internet connection is bad(i noticed it), maybe i use subscription wrong.

My code looks like:

String sub = mMeteor.subscribe("blabla");

And inside onDataAdded() i just parse the json and add it to a listview. Sometimes i call the same subscription few times. Is it wrong?

ocram commented 8 years ago

Thanks for your question!

Your code

String sub = mMeteor.subscribe("blabla");

is correct. In addition to that, however, you may listen for the status of this subscription by providing a callback as the second parameter. Please see the README for more details.

And onDataAdded is, as you said, where you should receive the documents. You may either parse the JSON yourself, as you said, or use the built-in database.

So everything is correct thus far.

Sometimes i call the same subscription few times.

This is most probably wrong, however. Why are you doing this? Because you feel you're missing documents that the server should be sending?

Are there any connection issues during the time you observe this? Is the connection lost sometimes and re-established?

Maybe issue https://github.com/delight-im/Android-DDP/issues/74 is related.

PavelEgorov1 commented 8 years ago

This is most probably wrong, however. Why are you doing this? Because you feel you're missing documents that the server should be sending?

Yes,i notice that sometimes i can miss the sendings.

Are there any connection issues during the time you observe this? Is the connection lost sometimes and re-established?

Yes, it can be issues with connection. I was advised to use thread to reconnect the application if connection is lost. Inside a thread i relogin and resubscribe to all subscriptions.

ocram commented 8 years ago

Did you look at the (possibly) related issue?

Why are you doing the re-connects manually? There's some built-in re-connect capability. Doesn't it work for you?

So if you ever subscribe to a resource twice, that should only be after establishing a new connection. As long as the same connection lives, you never have to subscribe more than once.

PavelEgorov1 commented 8 years ago

Why are you doing the re-connects manually? There's some built-in re-connect capability. Doesn't it work for you?

About what built-in re-connect capability did you write? How should i use it properly? I just made thread, that checks condition if(!mMeteor.isConnected) and reconnects user mMeteor.reconnect() every 5 seconds. I didn't find the other way to do reconnect a user.

So if you ever subscribe to a resource twice, that should only be after establishing a new connection. As long as the same connection lives, you never have to subscribe more than once.

When the connection is lost User log outs and subscriptions miss?

ocram commented 8 years ago

As you can see in the source code, this library should just re-connect automatically when it loses the connection. Is that not working?

After that automatic re-connect, the subscriptions may still be there. But if you connect again manually, I guess you have to set them up again yourself.

PavelEgorov1 commented 8 years ago

Subscription is still working with these issues. It occurs when Wi-Fi connection is bad, cause when i checks my application by driving to different places. Server sends me some data and i get no data in different places with different internet connection

And built-in re-connect function is not working. In first 5 minutes it works, but after it sends like waterfall (in one second 100+ times) strange information like:

payload == {"msg":"result","id":"1f44a988-aaac-44b0-b448-227cbe040cad","result":"FHeFPBCra2LBJYBcd"}`
I/System.out: Meteor
I/System.out:   onTextMessage
I/System.out:     payload == {"msg":"updated","methods":["c0db86c1-7829-40e8-a0df-b76fb4c9e2b4"]}

My app was overloaded and stop to work with this built-in re-connect function.

ocram commented 7 years ago

We'll track the issue with the automatic re-login in https://github.com/delight-im/Android-DDP/issues/98 and the issue with subscriptions not working correctly is probably related to https://github.com/delight-im/Android-DDP/issues/74.