New media added server-side was invisible while the app was open - the client had no channel for library-change notifications, so the home screen and library tabs sat stale until an app restart. Each online server now runs a reconnecting websocket push channel (Plex `/:/websockets/notifications`; Jellyfin/Emby `/socket` with the dialect deltas, including Emby's capabilities registration), owned per server by a LibraryEventService supervisor that follows server online/offline/replaced-client transitions and app lifecycle. Channels emit one coalesced LibraryChangeEvent per burst on a leading-edge throttle modeled on Plex Web's repopulate pacing: the first settled change surfaces immediately and a library scan's flood merges behind it. Connection failure degrades silently to the stale-refresh paths - bounded reconnect backoff, re-armed on every status sync. Consumers pace their reaction through one shared RefreshPacer: burst debounce, blocked retry while video playback or an active scroll owns the surface, a cooldown bounding pass frequency during bulk imports, and credit for committed pull passes so a push landing right after a fresh load defers to the cooldown's trailing edge. - Discover runs a debounced full pass and swaps the result in place; the hero carousel resets only when a pass lands first content, so a push never yanks a screen the user is reading. Pushed removals drop from every visible list immediately via the deletion bus, scoped to the emitting server. - The visible library tab swaps its data in place: transaction tabs reload without clearing, and the browse and paginated card grids refetch their loaded span (Plex Web's repopulateRange) with the scroll offset anchored on the first visible item and the span clamped after alpha jumps. Hidden tabs - and tabs behind another main tab - mark per-library staleness epochs instead and reload when next shown; epochs are snapshotted at load start so a push racing an in-flight fetch stays stale. - The stale-resume and tab-shown paths refetch home hubs (previously Continue Watching only), covering setups where the socket cannot connect. close #1646
19 lines
752 B
Dart
19 lines
752 B
Dart
import '../media/library_change_event.dart';
|
|
import 'base_notifier.dart';
|
|
|
|
/// App-global fan-out for server push notifications about library content
|
|
/// (#1646). [LibraryEventService] publishes one coalesced event per server
|
|
/// change burst; profile-scoped consumers ([DiscoverProvider] today) subscribe
|
|
/// through [stream] and refetch their own views.
|
|
///
|
|
/// Same singleton shape as [LibraryRefreshNotifier] / [WatchStateNotifier].
|
|
class LibraryContentNotifier extends BaseNotifier<LibraryChangeEvent> {
|
|
static final LibraryContentNotifier _instance = LibraryContentNotifier._internal();
|
|
|
|
factory LibraryContentNotifier() => _instance;
|
|
|
|
LibraryContentNotifier._internal();
|
|
|
|
void notifyChanged(LibraryChangeEvent event) => notify(event);
|
|
}
|