ok
Now keep an eye on it to see if it disconnects
ok
@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
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
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
In Flutter, the stream should have an onDone callback
ondone and onerror both are not firing when user switch the network and try to chat .
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.
I used the twitter clone by Rivaan as an example
some questions;
- what's your code?
- what version of the flutter SDK are you using?
- is your app running on android, ios, or web?
android and web
I don't see the onDone callback in listen()
in this code.
Also, I meant the Appwrite Flutter SDK version
please see the video i tested the issue in a demo code. appwrite version i use is 8.2.2
this is the test code i used.
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"); },
);
} catch (eee) {
print(eee);
}
}
my "onDone" works when it get cancelled on Android. I use Flutter 3.7, appwrite: ^8.2.2, Appwrite version 1.2
changing network means onDone wont work right ? . what about onerror ?
So far I haven't seen onError getting triggered
I wrote my own logic for network change
So it reconnects when it is back online
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
It would also not reconnect on my end
i am not really sure this is how to check network but nothing seems to happen to socket when i switch networks
Interesting...it doesn't look like it's closing π
Recommended threads
- Current User is Not authorized
recreating same Thread
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...