Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Stremio/stremio-core/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheCtx (Context) model is the central state container in Stremio Core. It manages all user-related data including authentication, library, notifications, streams, and application events.
Structure
Key Components
Profile
Contains user authentication and settings:The
addons_locked flag prevents overwriting user addons when API fetch fails and defaults to official addons are used.LibraryBucket
Manages the user’s library of media items:new(uid: UID, items: Vec<LibraryItem>)- Creates a new library bucketmerge_bucket(&mut self, bucket: LibraryBucket)- Merges another bucketmerge_items(&mut self, items: Vec<LibraryItem>)- Merges individual itemsare_ids_in_recent(&self, ids: &[String]) -> bool- Checks if IDs are recentsplit_items_by_recent(&self) -> (Vec<&LibraryItem>, Vec<&LibraryItem>)- Splits by recency
CtxStatus
Tracks authentication state:Authentication Flow
Login
Fetch User Data
Parallel requests for:
- Authentication token
- Addon collection
- Library items from datastore
Logout
Update Handlers
The Ctx model coordinates updates across all sub-modules:Sub-Update Modules
The Ctx delegates specific updates to specialized modules:| Module | File | Purpose |
|---|---|---|
| Profile | update_profile.rs | User auth and settings |
| Library | update_library.rs | Library item management |
| Notifications | update_notifications.rs | Notification handling |
| Streams | update_streams.rs | Stream tracking |
| Events | update_events.rs | Event management |
| Search History | update_search_history.rs | Search tracking |
| Streaming Server URLs | update_streaming_server_urls.rs | Server URL management |
| Trakt Addon | update_trakt_addon.rs | Trakt integration |
Events
Key events emitted by Ctx:Error Handling
Usage Example
Best Practices
State Synchronization
State Synchronization
The Ctx automatically synchronizes library and profile changes to the remote API when authenticated. Updates are batched and deduplicated for efficiency.
Error Recovery
Error Recovery
If addon fetch fails during authentication, the
addons_locked flag prevents local addon changes from syncing to the API, preserving user data.Analytics Flushing
Analytics Flushing
Before authentication requests, analytics are flushed to ensure data is captured before potential app state changes.
Related Models
- Library - Library item management
- Player - Media playback
- StreamingServer - Server communication
