Skip to main content
The Streampixel SDK Example is a React application that demonstrates a complete SDK integration. This page walks through its structure and key patterns.

Project structure

Setup and running

1

Clone the repository

2

Install dependencies

3

Start the dev server

Open http://localhost:3000/YOUR_PROJECT_ID in your browser.

URL parameters

The example reads configuration from the URL: Example URL: http://localhost:3000/abc123?sfuPlayer=true&streamerId=host1

Feature toggles

At the top of App.js:
Set SHOW_DEV_TOOLS to false before deploying to production. The Developer Tools panel exposes console commands, JSON messaging, and mic/camera controls that are intended for development only.

LOADING_CONFIG

The LOADING_CONFIG object is the easiest way to customize the loading experience. Change text, colors, and status messages in one place without modifying any event handler logic.
The example centralizes all loading screen text and colors in a single configuration object:
Modify this object to customize the loading experience without touching event handlers.

How the example wires SDK events

SDK initialization

The app initializes inside a useEffect hook that runs when projectId is available:

Lifecycle events to loading progress

Each WebRTC event updates React state for the loading screen:

Reconnection to loading screen

The reconnection state drives the loading screen back into view:

AFK warning to custom overlay

The example replaces the default AFK overlay with a styled card:
The dismiss button calls dismissAfkRef.current().

Developer Tools panel

When SHOW_DEV_TOOLS is true, the example shows a panel with these sections:

Stream controls toolbar

The bottom-right toolbar shows after loading completes:
  • Mute/Unmute — Toggles both video and audio elements
  • Fullscreen — Toggles browser fullscreen mode
  • Stream Info — Shows stats from UIControl.getStreamStats()
  • Settings (if resolution enabled) — Resolution selection dropdown
  • Dev Tools (if enabled) — Opens the Developer Tools panel

Key React patterns used

  • useRef for SDK instances (pixelStreamingRef, appStreamRef, uiControlRef) — avoids re-renders
  • useState for UI state (loading, controls, AFK, stats)
  • useCallback for event handlers (mute, fullscreen, dev tools actions)
  • mounted flag in useEffect to prevent state updates after unmount
  • Event handler stopPropagation on dev tools inputs to prevent keyboard events from reaching the stream

Next steps

Custom loading screen

Build a loading screen driven by SDK lifecycle events.

Troubleshooting

Resolve common SDK integration issues.