Welcome to @interactive-video-labs/react — a lightweight React wrapper around the @interactive-video-labs/core engine for cue-driven interactive video experiences.
This release tracks @interactive-video-labs/core ^0.3.1.
This wrapper makes it easy to embed interactive video players in React apps using familiar props and event handlers, while keeping close to the core API.
@interactive-video-labs/react is a thin React component that provides a convenient way to integrate interactive video experiences into your React applications. It leverages the powerful @interactive-video-labs/core engine, allowing you to easily manage video playback, cue points, and analytics within a familiar React paradigm.
- Easy Integration: Seamlessly embed interactive videos into your React components.
- Cue Point Management: Load and manage cue points for dynamic video interactions.
- Analytics Events: Receive detailed analytics events from the video player to track user engagement.
- Localization: Support for player localization through translations.
- Core 0.3.1 Features: Pass-through support for subtitles, interactions, debugger mode, decision adapters, and live sync.
- Imperative Controls: Optional React ref access to playback, state, cues, translations, decisions, and live sync.
- Direct Core API Access: Provides a React-friendly interface while maintaining close alignment with the core IVLabsPlayer API.
You can install the package using npm or pnpm:
pnpm add @interactive-video-labs/react @interactive-video-labs/core react react-dom
# or
npm install @interactive-video-labs/react @interactive-video-labs/core react react-domTo use the InteractiveVideo component, simply import it and pass the necessary props. The videoUrl prop is mandatory.
import React from 'react';
import { InteractiveVideo } from '@interactive-video-labs/react';
const MyVideoPlayer = () => {
return (
<div style={{ width: '100%', maxWidth: '800px', margin: '0 auto' }}>
<InteractiveVideo
videoUrl="https://interactive-video-labs.github.io/interactive-video-demos/videos/big_buck_bunny.mp4"
autoplay={true}
loop={false}
onAnalyticsEvent={(event, payload) => {
console.log('Analytics Event:', event, payload);
// Handle analytics events, e.g., send to a tracking service
}}
cues={[
{
id: 'segmentChange',
time: 10,
label: 'Segment Change',
payload: {
interaction: {
type: 'choice-video-segment-change',
title: 'Choose your path',
description: 'Select a video segment to jump to.',
question: 'Where would you like to go?',
options: [
{
level: 'Segment A',
video:
'https://interactive-video-labs.github.io/assets/sample-interaction-1.mp4',
},
{
level: 'Segment B',
video:
'https://interactive-video-labs.github.io/assets/sample-interaction-2.mp4',
},
],
},
},
},
]}
translations={{
en: {
play: 'Play Video',
pause: 'Pause Video',
},
}}
debugger={true}
onLiveSyncStatus={(status) => {
console.log('Live sync status:', status);
}}
/>
</div>
);
};
export default MyVideoPlayer;The InteractiveVideo component accepts the following props:
videoUrl(string, required): The URL of the video to be played.onAnalyticsEvent(function, optional): A callback function that is triggered when an analytics event occurs. It receives theeventname and an optionalpayload.- Includes core events such as
PLAYER_LOADED,VIDEO_STARTED,VIDEO_PAUSED,CUE_LOADED,CUE_TRIGGERED,INTERACTION_SHOWN,INTERACTION_COMPLETED,VIDEO_ENDED,PLAYER_DESTROYED,ERROR, and the normalized analytics hooks. payload: An object containing event-specific data.
- Includes core events such as
cues(CuePoint[], optional): An array of cue points to load into the player. EachCuePointobject should conform to the@interactive-video-labs/coreCuePointinterface.translations(Record<string, Translations>, optional): A locale-to-translations map for player localization.onLiveSyncEvent(function, optional): Receives normalized live sync events such as room state, cue, decision, poll, and presence updates.onLiveSyncStatus(function, optional): Receives live sync connection lifecycle updates....restOptions(PlayerConfig, optional): Any other validPlayerConfigoptions from@interactive-video-labs/core(excludingvideoUrl,cues, andtranslations). This allows for direct pass-through of core player configurations likeautoplay,loop,subtitlesUrl,locale,interactions,debugger,liveSync, and decision adapters.
The component forwards a ref for core player operations:
import { useRef } from 'react';
import {
InteractiveVideo,
type InteractiveVideoHandle,
} from '@interactive-video-labs/react';
const playerRef = useRef<InteractiveVideoHandle>(null);
<InteractiveVideo ref={playerRef} videoUrl="/video.mp4" />
playerRef.current?.play();
playerRef.current?.pause();
const state = playerRef.current?.getState();Available methods include play, pause, syncToLive, getState, setLocale, loadCues, loadTranslations, getDecisionHistory, clearDecisionHistory, sendLiveSyncMessage, and getPlayer.
To set up the development environment:
- Clone the repository.
- Install dependencies:
pnpm install
- Build the project:
pnpm build
- Run tests:
pnpm test - Run examples:
pnpm serve-examples
We welcome contributions! Please see our CONTRIBUTING.md for more details.
This project is licensed under the MIT License. See the LICENSE file for details.