# Stremio Web
Stremio Web is a modern media center web application built with React that provides a one-stop solution for video entertainment. Users can discover, watch, and organize video content from easy-to-install addons. The application uses a modular architecture with a core transport layer communicating via Web Workers with the stremio-core-web Rust/WASM backend for performance-critical operations.
The application features a hash-based routing system, comprehensive player controls with Chromecast support, addon management, library organization, content discovery, and calendar tracking for series. It supports multiple platforms including web browsers, desktop (via Electron shell), and mobile devices with platform-specific features like external player integration.
## Core Services
### Core Service Initialization
The Core service manages the connection to the stremio-core-web backend through a Web Worker bridge. It handles state synchronization, user authentication, library management, and addon communication.
```javascript
// Initialize core service with app version
const services = {
core: new Core({
appVersion: process.env.VERSION,
shellVersion: null
}),
shell: new Shell(),
chromecast: new Chromecast(),
keyboardShortcuts: new KeyboardShortcuts(),
dragAndDrop: new DragAndDrop({ core })
};
// Start all services
services.core.start();
services.shell.start();
services.chromecast.start();
// Listen for state changes
services.core.on('stateChanged', () => {
if (services.core.active) {
console.log('Core is ready');
} else if (services.core.error) {
console.error('Core failed to initialize:', services.core.error);
}
});
// Dispatch actions to core
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'PullAddonsFromAPI'
}
});
// Get state from core
const ctx = await services.core.transport.getState('ctx');
console.log('User profile:', ctx.profile);
```
### CoreTransport API
The CoreTransport provides the bridge interface for communicating with the stremio-core-web WASM module running in a Web Worker.
```javascript
// CoreTransport methods available via services.core.transport
// Get model state
const playerState = await core.transport.getState('player');
const libraryState = await core.transport.getState('library');
const ctxState = await core.transport.getState('ctx');
// Dispatch actions
await core.transport.dispatch({
action: 'Load',
args: {
model: 'CatalogsWithExtra',
args: { extra: [['search', 'matrix']] }
}
}, 'catalog');
// Send analytics events
await core.transport.analytics({
event: 'LocationPathChanged',
args: { prevPath: '/board' }
});
// Decode stream for playback
const decodedStream = await core.transport.decodeStream(streamData);
// Listen for core events
core.transport.on('CoreEvent', ({ event, args }) => {
if (event === 'SettingsUpdated') {
console.log('Settings changed:', args.settings);
}
});
// Listen for state updates
core.transport.on('NewState', (models) => {
console.log('Updated models:', models);
});
```
## React Hooks
### useModelState Hook
The useModelState hook subscribes to core state models and automatically updates when the model changes. It handles state mapping, throttling, and cleanup.
```javascript
const useModelState = require('stremio/common/useModelState');
// Basic usage - subscribe to streaming server state
const useStreamingServer = () => {
return useModelState({ model: 'streaming_server' });
};
// With state mapping - transform ctx state to profile
const useProfile = () => {
const map = (ctx) => ({
...ctx.profile,
settings: {
...ctx.profile.settings,
streamingServerWarningDismissed: new Date(
ctx.profile.settings.streamingServerWarningDismissed
)
}
});
return useModelState({ model: 'ctx', map });
};
// With action dispatch on mount
const usePlayer = (urlParams) => {
return useModelState({
model: 'player',
action: {
action: 'Load',
args: {
model: 'Player',
args: { stream: urlParams.stream }
}
}
});
};
// Usage in component
const MyComponent = () => {
const profile = useProfile();
const streamingServer = useStreamingServer();
return (
User: {profile.auth?.user?.email}
Server: {streamingServer.baseUrl}
);
};
```
### useBinaryState Hook
A simple hook for managing boolean state with explicit on/off/toggle functions.
```javascript
const useBinaryState = require('stremio/common/useBinaryState');
const MyComponent = () => {
const [isOpen, open, close, toggle] = useBinaryState(false);
return (
);
};
// Navigate to addon details via URL
window.location.href = '#/addons?addon=' + encodeURIComponent('https://example.com/manifest.json');
```
## Application Constants
### Configuration Constants
Global constants used throughout the application for configuration and UI options.
```javascript
const CONSTANTS = require('stremio/common/CONSTANTS');
// Streaming server default URL
console.log(CONSTANTS.DEFAULT_STREAMING_SERVER_URL); // 'http://127.0.0.1:11470/'
// Chromecast configuration
console.log(CONSTANTS.CHROMECAST_RECEIVER_APP_ID); // '1634F54B'
// Subtitle customization options
console.log(CONSTANTS.SUBTITLES_SIZES); // [75, 100, 125, 150, 175, 200, 250]
console.log(CONSTANTS.SUBTITLES_FONTS); // ['PlusJakartaSans', 'Arial', ...]
// Player settings
console.log(CONSTANTS.SEEK_TIME_DURATIONS); // [3000, 5000, 10000, ...]
console.log(CONSTANTS.NEXT_VIDEO_POPUP_DURATIONS); // [0, 5000, 10000, ...]
// Catalog pagination
console.log(CONSTANTS.CATALOG_PREVIEW_SIZE); // 10
console.log(CONSTANTS.CATALOG_PAGE_SIZE); // 100
// Content type priorities for sorting
console.log(CONSTANTS.TYPE_PRIORITIES);
// { movie: 10, series: 9, channel: 8, tv: 7, music: 6, ... }
// External player options by platform
const externalPlayers = CONSTANTS.EXTERNAL_PLAYERS.filter(
player => player.platforms.includes('android')
);
// VLC, MX Player, Just Player, etc.
// Supported local subtitle formats
console.log(CONSTANTS.SUPPORTED_LOCAL_SUBTITLES);
// ['application/x-subrip', 'text/vtt']
// Deep link protocol
console.log(CONSTANTS.PROTOCOL); // 'stremio:'
```
## Summary
Stremio Web is designed for building rich media experiences with a focus on extensibility through addons and cross-platform compatibility. The architecture separates concerns between the React UI layer and the Rust/WASM core, communicating through a Web Worker bridge for optimal performance. Key patterns include the useModelState hook for reactive state management, hash-based routing for deep linking support, and the services layer for platform-specific functionality like Chromecast and shell integration.
Developers extending Stremio Web should focus on the addon system for adding new content sources, the component library for UI consistency, and the core dispatch/state pattern for data flow. The application supports multiple deployment targets including standalone web, Electron desktop, and mobile webviews, with platform detection enabling conditional features. The toast and tooltip systems provide consistent user feedback, while the router supports complex navigation patterns with parameter extraction and view stacking.