Core service is the central bridge between the Stremio Web frontend and the stremio-core-web Rust backend. It manages a CoreTransport that runs the core logic inside a WebWorker, and exposes a simple lifecycle API for starting, stopping, and observing state.
Constructor
Initialization arguments forwarded verbatim to the core WebWorker via
bridge.call(['init'], [args]). The shape of this object is determined by the stremio-core-web init contract.Properties
All properties are read-only (defined withObject.defineProperties).
true when the underlying CoreTransport has successfully initialized. Resets to false when stop() is called or an error occurs.Set to an
Error instance if the transport fails to initialize ('Stremio Core Transport initialization failed'). null otherwise, or after stop() clears it.true while the transport is being created and waiting for the init event. Resets to false once initialization succeeds or fails.The active
CoreTransport instance, or null when the service is not running.Methods
start()
Initializes the CoreTransport and begins the connection to the core WebWorker. Does nothing if the service is already active, starting, or has an error.
start() is idempotent only in the sense that it exits early when already running or errored. To retry after an error, call stop() first — but note that once error is set, stop() must be called to clear it before start() will run again.stop()
Tears down the transport and resets all state (active, error, starting) to their defaults. Safe to call at any time.
on(name, listener)
Registers a listener on the internal EventEmitter.
The event name. Currently only
'stateChanged' is emitted by Core itself.Callback invoked when the event fires.
off(name, listener)
Removes a previously registered listener.
The event name.
The exact function reference passed to
on().Events
Emitted whenever any of
active, error, or starting changes. Consumers should re-read these properties after receiving this event.CoreTransport
CoreTransport wraps the stremio-core-web bridge and WebWorker. It is created internally by Core.start() and exposed via core.transport.
Constructor
- Spawns a WebWorker at
${COMMIT_HASH}/scripts/worker.js. - Creates a
Bridgebetweenwindowand the worker. - Calls
bridge.call(['init'], [args])— emitting'init'on success or'error'on failure. - Installs
window.onCoreEventto forward core runtime events into the transport’s event emitter.
Methods
Fetches the current state of a named model from the core.
The model name to retrieve.
Returns the full debug state from the core with no arguments.
Decodes a raw stream descriptor string into a structured
Stream object.The raw stream string to decode.
Sends an analytics event to the core. Also passes
location.hash as context.Subscribe to transport-level events (
'init', 'error', plus any events forwarded from window.onCoreEvent).Unsubscribe from a transport-level event.
Removes all listeners. Called internally by
Core.stop().Usage example
The
Core service is a singleton in practice — only one instance should be created per application session. All components that need to interact with the core access it through the shared instance.