Closed bstillitano closed 5 years ago
Sample Activity here:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
initParse(this)
}
fun initParse(context: Context) {
//Setup Parse
Parse.initialize(
Parse.Configuration.Builder(context)
.applicationId("applicaitonId")
.clientKey("clientKey")
.server("serverURL")
.enableLocalDataStore()
.build()
)
//Setup Config
ParseConfig.getInBackground()
//Sample LiveQuery
startListeningToNotifications()
}
fun startListeningToNotifications() {
//Build Live Query Client
val parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient()
//Build Query
var parseQuery = ParseQuery.getQuery<ParseObject>("Notifications")
parseQuery.whereEqualTo("toUser", ParseUser.getCurrentUser())
parseQuery.orderByAscending("createdAt")
parseQuery.findInBackground { objects, e ->
//Do something with notifications
}
//Build Live Query Listener
var subscriptionHandling: SubscriptionHandling<ParseObject> = parseLiveQueryClient.subscribe(parseQuery)
subscriptionHandling.handleSubscribe {
Toast.makeText(this, "SUBSCRIBED", Toast.LENGTH_LONG).show()
}
subscriptionHandling.handleEvents { query, event, `object` ->
Toast.makeText(this, "EVENT RECEIVED", Toast.LENGTH_LONG).show()
}
subscriptionHandling.handleError { query, exception ->
Toast.makeText(this, exception.message, Toast.LENGTH_LONG).show()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return when (item.itemId) {
R.id.action_settings -> true
else -> super.onOptionsItemSelected(item)
}
}
}
Anything on this?
This is what i did.
Important Make Sure, your parse server version grater than 2.8.4. Enable live query from Back4App by activating "Activate Back4App Hosting", create a subdomain, select all table that you want to live query.
Important
parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(URI("wss://" + context!!.getString(R.string.live_query_app_name) + ".back4app.io/"))
live_query_app_name is your subdomain
Handle single event instead of multiple
subscriptionHandling = parseLiveQueryClient!!.subscribe(requestStatusLiveQuery)
subscriptionHandling!!.handleEvent(SubscriptionHandling.Event.CREATE) { query, `object` -> }
subscriptionHandling!!.handleEvent(SubscriptionHandling.Event.UPDATE) { query, `object` ->}
subscriptionHandling!!.handleEvent(SubscriptionHandling.Event.DELETE) { query, `object` -> }
Still working good for me..
You can try this: https://github.com/rommansabbir/ParseLiveQuery-Android/
Hello @bstillitano thank you for trying live query
however the subscription seems to just be failing completely Can you details on this. Do you see any relevant logs on the client Or on the server?
Thanks
@rommansabbir please stop. As many people have said, your solution only works for back4app and not the common setup of self hosted parse instances.
@mmimeault thanks for taking the time to look at this. I truly do appreciate it. I am not seeing any client side errors or server side errors or logs.
The strange thing is though that this works fine when run in a Java project which leads me to believe that there may be something wrong with the Kotlin implementation/migration of this library.
When I say
however the subscription seems to just be failing completely
I mean that none of the subscription events are being fired including errors, subscriptions and object updates
Any help is appreciated.
Thanks, but you should mentioned first that you are not using Back4App. Best of luck
On Tue, Apr 23, 2019, 8:08 PM bstillitano notifications@github.com wrote:
@rommansabbir https://github.com/rommansabbir please stop. As many people have said, your solution only works for back4app and not the common setup of self hosted parse instances.
@mmimeault https://github.com/mmimeault thanks for taking the time to look at this. I truly do appreciate it. I am not seeing any client side errors or server side errors or logs.
The strange thing is though that this works fine when run in a Java project which leads me to believe that there may be something wrong with the Kotlin implementation/migration of this library.
Any help is appreciated.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/parse-community/ParseLiveQuery-Android/issues/103#issuecomment-485818997, or mute the thread https://github.com/notifications/unsubscribe-auth/AGF7PA4VIJTNKKCS4TWBZVTPR4J7HANCNFSM4HFERK3A .
@mmimeault are you able to assist with this?
Wondering if this is of any help to you @mmimeault. Really need to get this issue resolved as over on StackOverflow, multiple people are having the same issue.
Hello, It is really to debug that kind of issue remotely. I have been using this live query client since the beginning and it is still working perfectly.
If you put some breakpoint into the OkHttp3WebSocketClient, do you any of the callback methods called? Maybe there is an error not thrown back to the live query client.
There is 5 callback to the okhttp3 websocket client (WebSocketListener). onOpen, onMessage(2), onClosed and onFailure. Maybe putting some breakpoints there will help us debug the issue. Any of those method are called when starting the subscription?
Thanks
@mmimeault you're right. I'm getting the following stacktrace when subscribing to any queries:
Do you have any guidance on where to from here? LiveQuery is definitely running.
Just before digging into the error itself, you should add this callback after getting the client from the factory
parseLiveQueryClient.registerListener(new ParseLiveQueryClientCallbacks() {
@Override
public void onLiveQueryClientConnected(ParseLiveQueryClient client) {
}
@Override
public void onLiveQueryClientDisconnected(ParseLiveQueryClient client, boolean userInitiated) {
}
@Override
public void onLiveQueryError(ParseLiveQueryClient client, LiveQueryException reason) {
}
@Override
public void onSocketError(ParseLiveQueryClient client, Throwable reason) {
}
});
You would get the error you see in your debugger in that onSocketError callback.
I am not an expert about sockets nor the parse server implementation. But from what I can understand here, it seem to be an issue with your server. 1- Did you enabled LiveQuery on the parse server? 2- Is the port opened ? Maybe it is blocked by a firewall or routing. Where is your parse server hosted?
Maybe you can try just simply opening a connection to the port in the terminal. You can use telnet
to do it. (telnet hostname port
) (brew install telnet, if not installed and you are using a mac)
But if it failed at this point with that kind of error, I'm 99.99% sure it is one of the issue I mentioned above.
@bstillitano Can you explain why you closed the ticket. Thanks
@mmimeault I closed it because I resolved the issue.
Using your tip of debugging the socket, I found that I was getting a 403. I thought this may have been a setup issue on my end so changed a few things around but this did not help.
After restoring my server to its original setup, I found that by specifying the port directly in the parse server URL in the SDK it connects properly and subscriptions work fine.
Tried with a back4app and heroku setup along with my google cloud setup and all to the same result so this looks like a limit of the SDK or OkHttp
It is not a limit of the SDK or OkHttp to have to specify the port, if you are using a non-standard port, it makes sense that you would have to specify it.
I don’t have a special configuration....I tried with multiple ports and the default configurations recommended in the Parse Docs. Happened across multiple servers, providers and configurations also.
This is quite obviously a limitation of the SDK and it would not go astray to mention that if you are seeing no callbacks to make sure that you are specifying the port in your server URL.
On Sun, 5 May 2019 at 2:05 am, John Carlson notifications@github.com wrote:
It is not a limit of the SDK or OkHttp to have to specify the port, if you are using a non-standard port, it makes sense that you would have to specify it.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/parse-community/ParseLiveQuery-Android/issues/103#issuecomment-489340001, or mute the thread https://github.com/notifications/unsubscribe-auth/AJVMONX6VJER5UDX3YXGJ7TPTWX4RANCNFSM4HFERK3A .
I've set up quite a few Parse server instances on many different providers with the standard setup and have never had to specify the port in the Android SDK. Feel free to open a PR on the docs if you would like.
I am subscribing to a query on a table that has liveQuery enabled however the subscription seems to just be failing completely. The code is below:
Any help with this is highly appreciated. I have looked at @rommansabbir project and it does nothing that the example project doesn't show us. Really stuck on this one.