Back

Detailed logs for realtime

  • 0
  • Realtime
panda_p
8 Jun, 2023, 11:47

Interesting. I was about to open a new thread for this topic. Lost internet connection is the keyword. Are there best practises to handle this on the smartphone-app using realtime.

TL;DR
Summary: The user is experiencing issues with the automatic reconnection of a real-time connection when leaving airplane mode. They have tried different configurations and versions of the appwrite and flutter packages, but the issue persists. The user suggests that the SDK should handle the reconnection automatically. They share some relevant links to discussions and issues related to the problem. Solution: No solution provided in the support thread.
panda_p
8 Jun, 2023, 11:47

Because obviously I am doing it wrong.

Drake
8 Jun, 2023, 14:42

I think the SDK should automatically re-connect. Are you saying you don't get reconnected and you don't get any indication it's no longer connected? What's your code?

And are you on flutter web or mobile?

panda_p
8 Jun, 2023, 17:16

It would be great if re-connecting would be handled by the SDK. But using the android emulator and appwrite on my local machine the SDK does not automatically reconnect realtime. Realtime works fine until I disable and reenable the internet connection in the emulator. The realtime-server still sends events, but they don't reach my code anymore. Neither the onDone() nor the onError() callback of the realtime.subscribe(...).stream.listen() fire. So yes, judging from the appwrite-realtime-server log and the logs from my app, I don't get any indication that the realtime-connection is no longer working.

I am using flutter with appwrite: ^9.0.0 and riverpod. As for my code, there is exactly one realtime instance that subscripes once to all channels I need for the app. I then register and unregister clients to receive events when needed.

I will now try the same code on a real device using a different appwrite installation.

panda_p
8 Jun, 2023, 17:20

Something strange happened again. After disconnecting and reconnecting the app and confirming that the app does no longer receive realtime events, after some time the appwrite-realtime-server closed the connection. AND the onDone() in my app got called. How does that make any sense? Still on the emulator.

Drake
8 Jun, 2023, 17:21

so i have this code:

TypeScript
    subscription = realtime.subscribe(['files', 'documents']);
    subscription!.stream.listen((data) {
      print(data);
      setState(() {
        realtimeEvent = jsonEncode(data.toMap());
      });
    }, onError: (e) {
      print(e);
    }, onDone: () {
      print('done');
    });

and when i turned on airplaine mode, done was printed

panda_p
8 Jun, 2023, 17:28

Hm... onDone() does not get fired for me. I have two thoughts:

  • I am killing the internet connection not through airplane mode, but by manually switching off wifi and mobile data. Maybe that is a difference? But onDone() does not get called either.
  • I am using connectivity_plus to detect when the app loses internet connection. Maybe that is intercepting the event to propagate further?
panda_p
8 Jun, 2023, 17:36

I will minimize my code further and see where that gets me.

Drake
8 Jun, 2023, 17:43

Let me check by turning off wifi and mobile data

Drake
8 Jun, 2023, 17:59

so it also prints done if i turn off mobile data and wifi

panda_p
8 Jun, 2023, 18:01

What version of appwrite-sdk do you use? I cannot bring onDone() to fire. I see '!! build' and '!! data' on my first test, but no '!! done' when turning off interent, regardless of method. Still on eulator.

panda_p
8 Jun, 2023, 18:04

Oh, and appwrite 1.3.4

Drake
8 Jun, 2023, 18:05

9.0.0. im on a dev version of appwrite but that shouldn't make a difference.

Is this LoginPage widget maybe going away?

Drake
8 Jun, 2023, 18:06

also..i wouldn't do this in build πŸ‘€ at the very least, it should be in initstate

panda_p
8 Jun, 2023, 18:13

No difference :(. no '!! dispose' in the log. '!! data' in the log to ensure realtime is working before killing internet connection. I don't think the app ges any more minimal than this.

panda_p
8 Jun, 2023, 18:14

I am making a new blank app.

panda_p
8 Jun, 2023, 18:38

Still not working.

  • fresh project
  • only main.dart
  • only dependency is appwrite
  • realtime works until first disconnect
  • no done, no dispose
  • no automatic reconnect

I still use the same appwrite backend and the same project.

panda_p
8 Jun, 2023, 19:27

Also, Flutter 3.10.2 on Windows

Drake
9 Jun, 2023, 00:30

i just tested against cloud and it worked πŸ‘€

panda_p
9 Jun, 2023, 07:05

All right. As soon as I can (yesterday was a holiday so I had time to tinker) I will test using a real device and an appwrite in the cloud.

panda_p
9 Jun, 2023, 18:37

Running the minimal-app on a real device against an appwrite in the cloud does indeed trigger onDone() when entering airplane mode. Heaven knows why. Sadly, the realtime-connection is still not reestablished automatically when I leave airplane mode. Should it?

Drake
9 Jun, 2023, 18:40

Sadly, the realtime-connection is still not reestablished automatically when I leave airplane mode. Should it? @dlohani?

dlohani
11 Jun, 2023, 00:10

Not yet, for now you should get the onDone event on the stream you are listening to and you should reconnect yourself. I'm still figuring out a way to do it internally

Joshi
16 Aug, 2023, 17:47

I've used the https://pub.dev/packages/web_socket_client package and it works reliably. It has a retry function that reliably reconnects when the connection drops

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