Technical Deep Dive
The Signal Share Hero Player Architecture
This document details the underlying mechanisms, state management, and cross-device communication protocols used by the Hero Media Player. This guide is intended for developers integrating or debugging media playback features.
1. Component Overview & State Management
The Hero Player acts as the primary, unified media viewport. Its core responsibility is to abstract away the source complexity (YouTube embed vs. Spotify widget vs. local file upload) into a single, controllable playback interface.
State Variables (Client-Side Focus):
currentMediaSource: Determines the active playback mode ('youtube', 'spotify', 'local'). This dictates which embed/API is initialized.isPlaying: Boolean state tracking whether playback is currently active or paused.playbackContextId: A unique identifier generated upon loading a post, used to ensure that subsequent API calls target the correct session data within Supabase or locally.isDesktopBridgeActive: Tracks connectivity status with the local desktop bridge service.
Playback Lifecycle Flow:
- Initialization: On page load, the component listens for initial state from the global store (or URL parameters). The player defaults to a neutral/placeholder view.
- Source Loading: When
loadMedia(postData)is called, it first validatespostData.typeandpostData.url. It then calls source-specific handlers (initializeYoutubePlayer,initializeSpotifyClient). - State Update: Successful initialization updates the local state variables mentioned above, triggering a re-render of the player element.
2. Media Source Integration Details
YouTube Player Module:
Uses the standard YouTube IFrame API (or embedded player object). The key interaction point is calling player.playVideo() and listening to onStateChange events (e.g., YT.PlayerState.ENDED) for state synchronization.
Spotify Integration Module:
Relies on either a direct embedded widget or, for advanced control (e.g., track progress bar synchronization), requires interaction with an external Spotify Web API wrapper service.
Local/Uploaded Media:
For uploaded files, the player defaults to a standard HTML5 <video> element. Playback control is handled directly via JavaScript DOM manipulation (e.g., videoElement.play()). This path is the most resilient against external API changes.
3. Desktop Bridge IPC (Inter-Process Communication)
When isDesktopBridgeActive is true, the player switches control logic from client-side DOM controls to sending standardized commands over a local WebSocket connection established with the bridge service.
Protocol Details:
The communication uses JSON payloads sent over the local endpoint (typically ws://localhost:PORT).
Outgoing Commands (Client -> Bridge):
- Play Command:
{ "command": "PLAY", "mediaId": "..." } - Pause Command:
{ "command": "PAUSE" } - Next/Previous:
{ "command": "SEEK_ADJACENT", "direction": "next" | "prev" }
Incoming Events (Bridge -> Client):
The client must listen for status updates from the bridge. Example event:
{ "event": "STATE_UPDATED", "status": "PLAYING", "timeRemaining": 25 }
Security Note:
The optional Bridge Secret must be validated server-side (if using a dedicated backend endpoint to relay commands) or strictly checked against client input on the page level to prevent unauthorized control hijacking.
4. Local LLM Operation (AI Integration)
FEATURE ACTIVEFor advanced functionality like content generation, code help, or vision-based analysis, Signal Share supports integration with local Large Language Models (LLMs) running via tools like LM Studio or Ollama.
Compatible AI Models:
The companion is optimized for several modern architectures. For the best experience, we recommend the following models:
-
DeepSeek R1 Distill (Qwen 1.5B)
Ultra-fast, efficient, and perfect for low-VRAM setups. -
Gemma 4 (E2B / E4B)
Google's latest lightweight models, highly optimized for instruction following. -
Qwen 3.5 (9B / 4B)
High-performance reasoning and balanced technical capabilities. -
Qwen 3.5 VL (4B)
Vision-capable model used for analyzing screenshots and arcade UI. -
Qwen 2.5 Coder (7B)
Specialized for code generation, patching, and technical debugging. -
DeepSeek R1 (Qwen3 8B)
Strong reasoning performance with distill-enhanced weights.
Core Principles:
- Privacy: All processing happens on the user's hardware. No metadata is sent to external APIs.
- Latency: Zero network round-trip; speed is limited only by local GPU/CPU performance.
- Connectivity: Operates entirely offline using quantized model weights (GGUF).
Integration Pattern:
Similar to the Desktop Bridge, the AI module establishes a local WebSocket or HTTP connection to the LLM runner.
{ "action": "GENERATE_TAGS", "text": "A sunset over a digital ocean" }
Prerequisites for Local LLM Execution:
- LLM Runner Software: You must first install a local inference engine such as LM Studio, Ollama, or llama.cpp setup. This software manages the loading and running of model weights.
- Model Weights: Download a quantized version of the target LLM (e.g., Llama 3 GGUF format) that is compatible with your hardware's capabilities (GPU/RAM). The size dictates performance vs. resource usage.
- Port Binding: Configure the LLM Runner to expose an accessible local API endpoint (typically a WebSocket or HTTP REST interface) on a specific port (e.g., 12345).
Execution Flow Checklist (Client Perspective):
- Discovery: The client-side JS must first attempt to connect to the designated local API endpoint using a
fetchor WebSocket connection. - Connection Test: Validate connectivity and check for initial handshake success/failure. If it fails, show the 'LLM Unavailable' warning.
- Authentication: If required by your setup (e.g., API keys), securely retrieve and use credentials stored in a client-side config store (but never hardcoded).
- Request Dispatch: On user action, package the request JSON exactly as defined (
{ "action": "GENERATE_TAGS", ... }) and dispatch it to the established WebSocket/HTTP stream. - Response Handling: Process streamed responses. Streaming is preferred over waiting for a single large payload, allowing immediate UI feedback on token generation.
const ws = new WebSocket("ws://localhost:12345/llm");
ws.onmessage = (event) => { /* Handle streamed text */ };
Technical Considerations:
Implementations must verify available VRAM before loading heavy models to prevent system instability. The UI should gracefully degrade to manual entry if the local AI service is unavailable.
5. Hero Player Debugging Checklist
- [INIT] Did the component successfully read the
playbackContextIdfrom the session state? - [SOURCE VALIDATION] For YouTube/Spotify, is the source URL fully validated before attempting connection? (Check for malformed embed IDs).
- [STATE DRIFT] If playback seems stuck, manually force a state refresh by re-calling
loadMediawith the current post data. - [BRIDGE CHECK] Is the local desktop bridge running and accessible via WebSocket before attempting to send a command? Check console logs for connection errors on the client side.