As i don't want to download everytime mine app come to foreground (i.e. user shift to mine app from someother app)
realistically, not. iOS and Android can close background apps at any time.
You should be able to hook into lifecyle of your app using flutter. The realtime subscription should also have an onDone
callback
So when ondone is called, i can restart the connection again to keep it alive?
you can try...but again, don't expect it to stay connected if the app isn't in the foreground
Oh. Okay so it will again be killed. Better approach will be to check if it was closed and if yes then download the data when user comes again on foreground ?
you can either:
- use push notifications to send data to the device
- have a background job that tries to sync the data
Ok. Thanks ππ»
How to check if a realtime onnection is still active or not? When I closed the subscription it didn't gave any error but realtime was not active
I don't think the underlying websocket connection is exposed
I didn't understand what you mean. Can please explain more?
the websocket connection (https://github.com/appwrite/sdk-for-flutter/blob/f8480fdeecfb23782bd5b33d0e2a7db44fc8c391/lib/src/realtime_mixin.dart#L19) is a private property
So, my app was inactive for sometime and I updated a data to check realtime. But it didn't get updated in frontend. So subscribtion.close should have thrown the error which would have refreshed the data (i put it inside the error, so that if realtime was not active it should have refreshed the data). But it didn't worked
what version of the Appwrite Flutter SDK do you have and is your app running on mobile or web?
On flutter. And appwrite verison is 0.15.3 in server and flutter 6.0.0
ah ya...that version is older so you're affected by https://github.com/appwrite/sdk-for-flutter/issues/108
in short, in your version of the SDK, the realtime stream is not closed when the web socket closes
Ohh. So realtime was not active but it showed as active? As it didn't threw any error when I tried to close it? Any way to solve this issue or check it? So that I don't have to refresh data everytime my user brings app to foreground
if you need to be notified about when the websocket closes, you can refer to how it was fixed in the PR for that issue I linked. You may need to fork the SDK or something to apply the patch to the SDK for your version
Ok. These are the changes done to correct it? https://github.com/appwrite/sdk-for-flutter/commit/281e5d553fa7c25e6f5c9810cc73019648c99cca
Should, I directly change it in the src file of flutter and release it in the latest version, this will work right?
Thanks, these are the only lines that need to be changed, can you please confirm?
}, onDone: () {
for (var list in _channels.values) {
for (var stream in list) {
stream.close();
}
}
_closeConnection();
}, onError: (err, stack) {
for (var list in _channels.values) {
for (var stream in list) {
stream.sink.addError(err, stack);
}
}
if (_websok?.closeCode != null && _websok?.closeCode != 1008) {
debugPrint("Reconnecting in one second.");
Future.delayed(Duration(seconds: 1), _createSocket);
}
});
scanning quickly, it looks okay...
Ok. Thanks a lot ππ»
I updated the package file and tried many things but neither : onError or onDone worked! I don't know whats the issue
liveDataSubscription!.stream.listen((data) {
///
///
}, onDone: () {
print('On Done');
liveStreamBroken = true;
}, onError: (error, st) {
print('On Error - $error, $st');
liveStreamBroken = true;
});
It should have worked
I would use the debugger and step through to see what's going on
Recommended threads
- 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...
- [SOLVED] OAuth With Google & Flutter
Hi all, I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutte...