Closed chiragmittal19 closed 3 years ago
Not sure what you mean by a 'background service'. The client provides a subscription API which you can use whenever you need to presumably, what functionality do you think the client is missing?
When the app is killed, socket gets disconnected. Can there be a way to keep the socket connected and receive events?
There is the autoreconnect functionality available, if the client gets a disconnect indication from the broker socket it will try and reconnect automatically, however re-connection is of course dependent on the network availability, the client can't really control this.
What do you mean by 'when the app is killed'? How would the client keep the socket connected if its been killed?
I meant initializing the client in a background service which will keep on running even after the app is killed.
So what stops you doing this?
I guess there is no way to keep a service running in the background continously, in Flutter. Maybe not an issue in mqtt_client then.
@chiragmittal19 there's a hacky way using FlutterNativeView to run dart code in a background isolate. We are doing this rather successfully however it relies on a foreground service because background services aren't gaurunteed to run forever. If you need details message me I can dig up the links for references.
Hi, @justintime4tea Can you please share some code on how to do so in our case with mqtt_client here.
@chiragmittal19 there's a hacky way using FlutterNativeView to run dart code in a background isolate. We are doing this rather successfully however it relies on a foreground service because background services aren't gaurunteed to run forever. If you need details message me I can dig up the links for references.
Yeah, please provide us with some references. I don't know what but something stops me from being confident with this idea.
@uwejan, @chiragmittal19
We essentially followed this article with a few tweaks
“The Tricky Task of Keeping Flutter Running (Vol. 2)” by Pau Picas https://link.medium.com/vKb6F0vUo9
Can you try this?
It would be good to have a way to subscribe to a topic in a background service. The device will be able to receive events even after the app is killed.