Back

Any idle time limit on realtime ?

  • 0
  • Flutter
  • Realtime
Karthik
24 Feb, 2023, 05:09

ok

TL;DR
The user is experiencing issues with maintaining a websocket connection when switching networks. They have written their own logic for network changes but are not seeing the expected behavior with the onDone and onError callbacks. The user is running the app on Flutter version 3.7 and Appwrite version 8.2.2. They have provided a code snippet for reference. Other users suggest checking for network changes and invalidating the provider to force a reconnection. There is a mention of a known issue with websockets being terminated by certain browsers. The user is advised to keep an eye on the connection to see if it disconnects. No solution is provided
Drake
24 Feb, 2023, 05:13

Now keep an eye on it to see if it disconnects

Karthik
24 Feb, 2023, 05:13

ok

VincentGe
24 Feb, 2023, 15:53

@Karthik Depending on the browser, I've seen them terminating websockets after a while. I've had it happen on me for FB Messenger, too.

https://github.com/supabase/realtime-js/issues/121 https://github.com/SignalR/SignalR/issues/4536

VincentGe
24 Feb, 2023, 15:54

I think this might be a known issue? I've seen it pop up time to time. Might also be with certain browser builds? Not sure

Karthik
28 Feb, 2023, 17:59

Is there way to check if socket connection disconnect or not ? . i am also facing another issue if the user change his ip realtime stop working

Drake
28 Feb, 2023, 18:08

In Flutter, the stream should have an onDone callback

Karthik
1 Mar, 2023, 08:05

ondone and onerror both are not firing when user switch the network and try to chat .

Joshi
1 Mar, 2023, 13:50

I circumvent it by continuously checking for network changes or disruption and invalidate my provider which holds the realtime state so it can reconnect. It sends a GET request every 4 second (with a 3 second timeout) to my appwrite instance to see if it has a valid connection and to see if my appwrite instance is up. If connectivity changes for example Wlan gets turned off and switches to mobile it immediatley sends a GET request to my server. If connection drops at some point it will invalidate my provider to reconnect back to the websocket.

Joshi
1 Mar, 2023, 13:52

I used the twitter clone by Rivaan as an example

Drake
1 Mar, 2023, 16:28

some questions;

  1. what's your code?
  2. what version of the flutter SDK are you using?
  3. is your app running on android, ios, or web?
Karthik
2 Mar, 2023, 08:28

android and web

Drake
2 Mar, 2023, 16:22

I don't see the onDone callback in listen() in this code.

Also, I meant the Appwrite Flutter SDK version

Karthik
3 Mar, 2023, 08:21

please see the video i tested the issue in a demo code. appwrite version i use is 8.2.2

Karthik
3 Mar, 2023, 08:22

this is the test code i used.

Karthik
3 Mar, 2023, 08:22

create(BuildContext context) async { await sessionCreate(context, true, 95620444); final realtime = Realtime(client!); RealtimeSubscription subscription; try { subscription = realtime.subscribe([ 'databases.62f21a94d3a40d60445b.collections.62a899742200380b8ca7.documents' ]); subscription.stream.listen( (data) { print(data.payload); if (data.payload.isNotEmpty) { List<dynamic> ev = data.events; print(ev.elementAt(0)); String b = ev.elementAt(0); switch (data.events.elementAt(0)) { case 'databases.62f21a94d3a40d60445b.collections.62a899742200380b8ca7.documents..create': var item = data.payload; print(item); print("items added"); break; case "databases.62f21a94d3a40d60445b.collections.62a899742200380b8ca7.documents..delete": var item = data.payload; print(item); print("items deleted"); break; case "databases.62f21a94d3a40d60445b.collections.documents.update": var item = data.payload; print(item); print("items updated"); break; default: break; } } }, onDone: () { print("test"); },

TypeScript
  );
} catch (eee) {
  print(eee);
}

}

Joshi
3 Mar, 2023, 08:27

my "onDone" works when it get cancelled on Android. I use Flutter 3.7, appwrite: ^8.2.2, Appwrite version 1.2

Karthik
3 Mar, 2023, 08:52

changing network means onDone wont work right ? . what about onerror ?

Joshi
3 Mar, 2023, 08:57

So far I haven't seen onError getting triggered

Joshi
3 Mar, 2023, 08:57

I wrote my own logic for network change

Joshi
3 Mar, 2023, 08:57

So it reconnects when it is back online

Drake
3 Mar, 2023, 15:22

What was happening to the web socket connection when you switched networks?

I'm surprised events were still coming through after reconnecting to the original network

Joshi
3 Mar, 2023, 15:22

It would also not reconnect on my end

Karthik
6 Mar, 2023, 05:21

i am not really sure this is how to check network but nothing seems to happen to socket when i switch networks

Drake
6 Mar, 2023, 05:36

Interesting...it doesn't look like it's closing πŸ‘€

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