When the subscription auto-closes after 100 second, the key question is: How can we effectively handle scenarios where the user interacts with the app, actively listening, and then leaves the app in the background for an extended period before returning to reuse it? rebuild new subscription every 1 min better or make auto update every 1min for Prevent close the subscription
It shouldn't be auto closing after a minute? Is your server behind Cloudflare?
Yes, it is!
Yeah, IIRC, CF closes idle WebSockets connections after one to two minutes.
I don't think there's any way to disable that
If you want to automatically reopen, you could listen for the socket close event, and create a new connection when that happens?
It's after 100 seconds
i edited the first message for 100 seconds
Well, best would be to have that route bypass CF and not time out (I think that's possible, but not on the free plan. Alternatively, you could have a separate endpoint that doesn't go through CF for the WebSockets)?
Of course, once the user leaves the app in the background, it's likely it'll have all connections closed by battery saving, anyway. You could then recreate the onnection when the user re-enters the app
Should i keep sending a light request to refresh the subscription every 90 seconds or create a new subscription every 90 seconds which is better ?
If you have to choose between opening a new connection every minute and updating a document (to keep the connection alive) every minute, I'd say keep the connection alive
No,Now the question is: Sending a light request to refresh the subscription every 90 seconds or create a new subscription but when user interact with the app after 90 seconds (or more, may be 5 min) which is better ? what is the choosing caused ?
I assume by interact with the app you just mean the app is active?
I mean that the user is clicking on any part of the app screen.
Well, what are you using Realtime for?
I am using this for a chat AI app. There are instances when the user leaves the app without closing it.
But what are you doing with Realtime?
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...