A cross platform Audiobookshelf client for Android and iOS
Dart
Keep the server connection alive while the app is open instead of dropping it after five minutes
Barnabas0e25b5bcaba6
diff --git a/lib/providers/_lp_core.dart b/lib/providers/_lp_core.dartindex 7672de30..402cab00 100644--- a/lib/providers/_lp_core.dart+++ b/lib/providers/_lp_core.dart@@ -1030,11 +1030,14 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {if (!AudioPlayerService().isPlaying) {_stopLocalProbeTimer();}- _idleDisconnectTimer?.cancel(); // No timers in background- _idleDisconnectTimer = null;_softDisconnectSocket(); // Always disconnect, even during playback}+ // The socket stays connected the whole time the app is foregrounded: the+ // screen dominates battery while the app is visible, an idle websocket is+ // just ping frames, and live updates (progress sync, scan results) are worth+ // it. The old 5-minute foreground idle disconnect is gone; backgrounding+ // still tears the socket down.void onAppForegrounded() {_isBackgrounded = false;_softReconnectSocket();@@ -1044,27 +1047,15 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {_startHealthCheckTimer();}_startLocalProbeTimer();- _restartIdleTimer();if (!isOffline && !_manualOffline) {(this as LibraryProvider).checkSubscribedPodcasts();}}- void _restartIdleTimer() {- _idleDisconnectTimer?.cancel();- _idleDisconnectTimer = Timer(_StateMixin._idleTimeout, () {- if (!AudioPlayerService().isPlaying && !ChromecastService().isPlaying) {- _softDisconnectSocket();- }- });- }-void onPlaybackStarted() {if (!_isBackgrounded) {_softReconnectSocket();- } else {}- _idleDisconnectTimer?.cancel();_startLocalProbeTimer();}@@ -1072,8 +1063,6 @@ mixin _CoreMixin on ChangeNotifier, _StateMixin {if (_isBackgrounded) {_softDisconnectSocket();_stopLocalProbeTimer();- } else {- _restartIdleTimer();}}diff --git a/lib/providers/_lp_state.dart b/lib/providers/_lp_state.dartindex 50d1ab7f..053f0d9d 100644--- a/lib/providers/_lp_state.dart+++ b/lib/providers/_lp_state.dart@@ -82,8 +82,6 @@ mixin _StateMixin on ChangeNotifier {bool _isBackgrounded = false;bool _socketSoftDisconnected = false;- Timer? _idleDisconnectTimer;- static const _idleTimeout = Duration(minutes: 5);Map<String, Map<String, dynamic>> _progressMap = {};final Map<String, double> _localProgressOverrides = {};diff --git a/lib/providers/library_provider.dart b/lib/providers/library_provider.dartindex dfc59264..851faaee 100644--- a/lib/providers/library_provider.dart+++ b/lib/providers/library_provider.dart@@ -208,8 +208,6 @@ class LibraryProvider extends ChangeNotifier} else {_lastAuthKey = null;_lastUseLocalServer = null;- _idleDisconnectTimer?.cancel();- _idleDisconnectTimer = null;_libraries = [];_personalizedSections = [];_series = [];