Back

Appwrite Cloud Realtime subscription

  • 1
  • Flutter
  • Cloud
kamal.panara
1 Jan, 2024, 17:34

How to reconnect the realtime connection in Appwrite Flutter SDK when user leaves the app open in background connection closes after sometime and when user comes back to app realtime doesn't works.

same happens if user leaves the app open locks the phone and come back after sometime.

what is effecient way to reconnect?

TL;DR
The user is experiencing issues with the RealTime class in Appwrite Flutter SDK. Multiple subscribe calls on the same realtime instance causes the stream to stop emitting. There is no clear solution mentioned in the thread. However, suggestions include creating multiple real-time instances for each connection, using the onDone function of the stream, detecting when the app becomes active, preventing the app from being killed with a foreground service, and starting the subscription again if the app gets killed. The user is looking for an efficient way to reconnect the realtime connection when the app is left open or the phone is locked.
D5
1 Jan, 2024, 18:11

I think basically starting the subscription again if the app gets killed

D5
1 Jan, 2024, 18:11

I would try having a foreground service or something else to prevent the app from being killed

kamal.panara
1 Jan, 2024, 18:13

App is not being killed that’s the problem 😂 I have logic set-upped that closes the connection when app gets killed and when app opens it gets connected.

kamal.panara
1 Jan, 2024, 18:13

It’s like keeping the app open but just not using it, staying idle

ideclon
1 Jan, 2024, 22:16

Is there some way to detect when the app becomes active?

D5
1 Jan, 2024, 22:55

No idea, at least in the latest app I used realtime, it even tried to restart the connection automatically when it was lost

Drake
1 Jan, 2024, 23:05

There is a bug still in the flutter SDK where multiple subscribe calls on the same realtime instance causes the stream to stop emitting.

Otherwise, the stream has an onDone you can hook into for when the subscription closes

kamal.panara
2 Jan, 2024, 06:36

Okay so I need to create multiple real-time instances for each real-time connection

ideclon
2 Jan, 2024, 13:01

I’m not sure what you’re saying here? But this doesn’t sound right to me.

kamal.panara
2 Jan, 2024, 13:33

RealTime is class in Appwrite Flutter SDK. I’m saying for each unique connection I need to create new instance of RealTime class.

ideclon
2 Jan, 2024, 13:33

Ah - yes, that does sound correct!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more