@thewhateverapp/tile-sdk 0.11.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,12 +50,20 @@ export interface VideoContextValue {
50
50
  controls: VideoControls;
51
51
  videoRef: React.RefObject<HTMLVideoElement>;
52
52
  }
53
+ export interface CuePoint {
54
+ /** Time in seconds when the cue should trigger */
55
+ time: number;
56
+ /** Unique identifier for the cue point */
57
+ id: string;
58
+ /** Optional data to pass to the callback */
59
+ data?: unknown;
60
+ }
53
61
  export interface VideoPlayerProps {
54
62
  /** HLS playlist URL (m3u8) */
55
63
  src: string;
56
64
  /** Auto-start playback (default: true) */
57
65
  autoplay?: boolean;
58
- /** Loop video (default: false) */
66
+ /** Loop video (default: false, but true in preview mode) */
59
67
  loop?: boolean;
60
68
  /** Start muted (default: true for autoplay compliance) */
61
69
  muted?: boolean;
@@ -69,15 +77,103 @@ export interface VideoPlayerProps {
69
77
  className?: string;
70
78
  /** Video wrapper class names */
71
79
  videoClassName?: string;
80
+ /** Cue points for time-based triggers */
81
+ cuePoints?: CuePoint[];
82
+ /** Callback when a cue point is reached */
83
+ onCuePoint?: (cuePoint: CuePoint) => void;
84
+ /** Callback on time update (fires ~4 times per second) */
85
+ onTimeUpdate?: (currentTime: number, duration: number) => void;
72
86
  }
73
87
  /**
74
88
  * VideoPlayer component with HLS streaming support.
75
89
  * Provides video state and controls to child overlays via context.
90
+ *
91
+ * Features:
92
+ * - HLS streaming with automatic quality adaptation
93
+ * - Time-based cue points for triggering overlays
94
+ * - Visibility-aware playback (plays when visible, pauses when hidden)
95
+ * - Auto-loops in preview mode for testing
76
96
  */
77
- export declare function VideoPlayer({ src, autoplay, loop, muted, poster, controls, children, className, videoClassName, }: VideoPlayerProps): React.JSX.Element;
97
+ export declare function VideoPlayer({ src, autoplay, loop: loopProp, muted, poster, controls, children, className, videoClassName, cuePoints, onCuePoint, onTimeUpdate, }: VideoPlayerProps): React.JSX.Element;
78
98
  /**
79
99
  * Hook to access video state and controls from within VideoPlayer children.
80
100
  */
81
101
  export declare function useVideoState(): VideoContextValue;
102
+ /**
103
+ * Hook to trigger an action when a specific time is reached.
104
+ * Returns true when the video has reached or passed the specified time.
105
+ *
106
+ * @param triggerTime - Time in seconds when to trigger
107
+ * @param options - Configuration options
108
+ * @returns boolean indicating if the trigger time has been reached
109
+ *
110
+ * @example
111
+ * ```tsx
112
+ * function PollOverlay() {
113
+ * const showPoll = useCuePoint(5); // Show after 5 seconds
114
+ * return showPoll ? <Poll /> : null;
115
+ * }
116
+ * ```
117
+ */
118
+ export declare function useCuePoint(triggerTime: number, options?: {
119
+ /** Reset trigger when video loops (default: true) */
120
+ resetOnLoop?: boolean;
121
+ /** Trigger once or every time the time is crossed (default: 'once') */
122
+ mode?: 'once' | 'every-loop';
123
+ }): boolean;
124
+ /**
125
+ * Hook to manage multiple cue points with callbacks.
126
+ * More flexible than useCuePoint for complex time-based interactions.
127
+ *
128
+ * @param cuePoints - Array of cue points with times and callbacks
129
+ * @param options - Configuration options
130
+ *
131
+ * @example
132
+ * ```tsx
133
+ * function InteractiveOverlay() {
134
+ * const [showPoll, setShowPoll] = useState(false);
135
+ * const [showCTA, setShowCTA] = useState(false);
136
+ *
137
+ * useCuePoints([
138
+ * { time: 5, onTrigger: () => setShowPoll(true) },
139
+ * { time: 10, onTrigger: () => setShowCTA(true) },
140
+ * { time: 15, onTrigger: () => { setShowPoll(false); setShowCTA(false); } },
141
+ * ]);
142
+ *
143
+ * return (
144
+ * <>
145
+ * {showPoll && <Poll />}
146
+ * {showCTA && <CTAButton />}
147
+ * </>
148
+ * );
149
+ * }
150
+ * ```
151
+ */
152
+ export declare function useCuePoints(cuePoints: Array<{
153
+ /** Time in seconds when to trigger */
154
+ time: number;
155
+ /** Callback to execute when time is reached */
156
+ onTrigger: () => void;
157
+ /** Optional unique ID (defaults to index) */
158
+ id?: string;
159
+ }>, options?: {
160
+ /** Reset triggers when video loops (default: true) */
161
+ resetOnLoop?: boolean;
162
+ }): void;
163
+ /**
164
+ * Hook to get the current video progress as a percentage (0-100).
165
+ * Useful for progress bars or time-based animations.
166
+ *
167
+ * @returns Progress percentage (0-100)
168
+ *
169
+ * @example
170
+ * ```tsx
171
+ * function ProgressBar() {
172
+ * const progress = useVideoProgress();
173
+ * return <div style={{ width: `${progress}%` }} className="h-1 bg-white" />;
174
+ * }
175
+ * ```
176
+ */
177
+ export declare function useVideoProgress(): number;
82
178
  export {};
83
179
  //# sourceMappingURL=VideoPlayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VideoPlayer.d.ts","sourceRoot":"","sources":["../../../src/react/overlay/VideoPlayer.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAUf,UAAU,WAAW;IACnB,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,WAAW,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC/C,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IACpE,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,UAAU,SAAS;IACjB,WAAW,EAAE,MAAM,OAAO,CAAC;IAC3B,MAAM,EAAE;QACN,eAAe,EAAE,MAAM,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,UAAU,EAAE;QACV,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,KAAK,MAAM,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,OAAO,CAAA;KAA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AE,MAAM,IAAI,CAAC;IACtB,6CAA6C;IAC7C,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC,EACF,OAAO,GAAE;IACP,sDAAsD;IACtD,WAAW,CAAC,EAAE,OAAO,CAAC;CAClB,GACL,IAAI,CAgCN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC"}
@@ -2,13 +2,29 @@
2
2
  import React, { createContext, useContext, useEffect, useRef, useState, useCallback, } from 'react';
3
3
  import { getTileBridge } from '../../bridge/TileBridge';
4
4
  const VideoContext = createContext(null);
5
+ // Detect if we're in preview mode (tile-preview sets this global)
6
+ function isPreviewMode() {
7
+ if (typeof window === 'undefined')
8
+ return false;
9
+ return !!window.__PREVIEW_SESSION_ID__;
10
+ }
5
11
  /**
6
12
  * VideoPlayer component with HLS streaming support.
7
13
  * Provides video state and controls to child overlays via context.
14
+ *
15
+ * Features:
16
+ * - HLS streaming with automatic quality adaptation
17
+ * - Time-based cue points for triggering overlays
18
+ * - Visibility-aware playback (plays when visible, pauses when hidden)
19
+ * - Auto-loops in preview mode for testing
8
20
  */
9
- export function VideoPlayer({ src, autoplay = true, loop = false, muted = true, poster, controls = false, children, className = '', videoClassName = '', }) {
21
+ export function VideoPlayer({ src, autoplay = true, loop: loopProp, muted = true, poster, controls = false, children, className = '', videoClassName = '', cuePoints = [], onCuePoint, onTimeUpdate, }) {
10
22
  const videoRef = useRef(null);
11
23
  const hlsRef = useRef(null);
24
+ const triggeredCuePointsRef = useRef(new Set());
25
+ const lastTimeRef = useRef(0);
26
+ // Auto-enable loop in preview mode unless explicitly set to false
27
+ const loop = loopProp ?? isPreviewMode();
12
28
  const [state, setState] = useState({
13
29
  isPlaying: false,
14
30
  currentTime: 0,
@@ -127,7 +143,35 @@ export function VideoPlayer({ src, autoplay = true, loop = false, muted = true,
127
143
  return;
128
144
  const handlePlay = () => setState(s => ({ ...s, isPlaying: true }));
129
145
  const handlePause = () => setState(s => ({ ...s, isPlaying: false }));
130
- const handleTimeUpdate = () => setState(s => ({ ...s, currentTime: video.currentTime }));
146
+ const handleTimeUpdate = () => {
147
+ const currentTime = video.currentTime;
148
+ const duration = video.duration;
149
+ setState(s => ({ ...s, currentTime }));
150
+ // Call onTimeUpdate callback
151
+ if (onTimeUpdate && !isNaN(duration)) {
152
+ onTimeUpdate(currentTime, duration);
153
+ }
154
+ // Check cue points - trigger if we crossed the cue time since last update
155
+ if (onCuePoint && cuePoints.length > 0) {
156
+ const lastTime = lastTimeRef.current;
157
+ for (const cuePoint of cuePoints) {
158
+ const cueKey = `${cuePoint.id}-${Math.floor(currentTime / (duration || 1))}`;
159
+ // Trigger if we crossed the cue point time (handles both forward and loop)
160
+ // For looping: reset triggered cues when video loops back
161
+ if (currentTime < lastTime && lastTime > duration * 0.9) {
162
+ // Video looped - clear triggered cues
163
+ triggeredCuePointsRef.current.clear();
164
+ }
165
+ const alreadyTriggered = triggeredCuePointsRef.current.has(cueKey);
166
+ const crossedCuePoint = lastTime < cuePoint.time && currentTime >= cuePoint.time;
167
+ if (!alreadyTriggered && crossedCuePoint) {
168
+ triggeredCuePointsRef.current.add(cueKey);
169
+ onCuePoint(cuePoint);
170
+ }
171
+ }
172
+ }
173
+ lastTimeRef.current = currentTime;
174
+ };
131
175
  const handleDurationChange = () => setState(s => ({ ...s, duration: video.duration }));
132
176
  const handleVolumeChange = () => setState(s => ({ ...s, volume: video.volume, muted: video.muted }));
133
177
  const handleProgress = () => {
@@ -155,7 +199,7 @@ export function VideoPlayer({ src, autoplay = true, loop = false, muted = true,
155
199
  video.removeEventListener('progress', handleProgress);
156
200
  video.removeEventListener('error', handleError);
157
201
  };
158
- }, []);
202
+ }, [onTimeUpdate, onCuePoint, cuePoints]);
159
203
  // Visibility handling - play/pause based on tile visibility
160
204
  // Enables TikTok-style preloaded video tiles that only play when visible
161
205
  useEffect(() => {
@@ -213,3 +257,116 @@ export function useVideoState() {
213
257
  }
214
258
  return context;
215
259
  }
260
+ /**
261
+ * Hook to trigger an action when a specific time is reached.
262
+ * Returns true when the video has reached or passed the specified time.
263
+ *
264
+ * @param triggerTime - Time in seconds when to trigger
265
+ * @param options - Configuration options
266
+ * @returns boolean indicating if the trigger time has been reached
267
+ *
268
+ * @example
269
+ * ```tsx
270
+ * function PollOverlay() {
271
+ * const showPoll = useCuePoint(5); // Show after 5 seconds
272
+ * return showPoll ? <Poll /> : null;
273
+ * }
274
+ * ```
275
+ */
276
+ export function useCuePoint(triggerTime, options = {}) {
277
+ const { resetOnLoop = true, mode = 'once' } = options;
278
+ const { state } = useVideoState();
279
+ const [triggered, setTriggered] = useState(false);
280
+ const lastTimeRef = useRef(0);
281
+ useEffect(() => {
282
+ const { currentTime, duration } = state;
283
+ // Detect video loop (time jumped backwards significantly)
284
+ if (currentTime < lastTimeRef.current && lastTimeRef.current > duration * 0.9) {
285
+ if (resetOnLoop && mode === 'every-loop') {
286
+ setTriggered(false);
287
+ }
288
+ }
289
+ // Check if we crossed the trigger time
290
+ if (!triggered && currentTime >= triggerTime) {
291
+ setTriggered(true);
292
+ }
293
+ lastTimeRef.current = currentTime;
294
+ }, [state.currentTime, state.duration, triggerTime, triggered, resetOnLoop, mode]);
295
+ return triggered;
296
+ }
297
+ /**
298
+ * Hook to manage multiple cue points with callbacks.
299
+ * More flexible than useCuePoint for complex time-based interactions.
300
+ *
301
+ * @param cuePoints - Array of cue points with times and callbacks
302
+ * @param options - Configuration options
303
+ *
304
+ * @example
305
+ * ```tsx
306
+ * function InteractiveOverlay() {
307
+ * const [showPoll, setShowPoll] = useState(false);
308
+ * const [showCTA, setShowCTA] = useState(false);
309
+ *
310
+ * useCuePoints([
311
+ * { time: 5, onTrigger: () => setShowPoll(true) },
312
+ * { time: 10, onTrigger: () => setShowCTA(true) },
313
+ * { time: 15, onTrigger: () => { setShowPoll(false); setShowCTA(false); } },
314
+ * ]);
315
+ *
316
+ * return (
317
+ * <>
318
+ * {showPoll && <Poll />}
319
+ * {showCTA && <CTAButton />}
320
+ * </>
321
+ * );
322
+ * }
323
+ * ```
324
+ */
325
+ export function useCuePoints(cuePoints, options = {}) {
326
+ const { resetOnLoop = true } = options;
327
+ const { state } = useVideoState();
328
+ const triggeredRef = useRef(new Set());
329
+ const lastTimeRef = useRef(0);
330
+ useEffect(() => {
331
+ const { currentTime, duration } = state;
332
+ // Detect video loop
333
+ if (currentTime < lastTimeRef.current && lastTimeRef.current > duration * 0.9) {
334
+ if (resetOnLoop) {
335
+ triggeredRef.current.clear();
336
+ }
337
+ }
338
+ // Check each cue point
339
+ for (let i = 0; i < cuePoints.length; i++) {
340
+ const cue = cuePoints[i];
341
+ const cueId = cue.id ?? `cue-${i}`;
342
+ const alreadyTriggered = triggeredRef.current.has(cueId);
343
+ const crossedTime = lastTimeRef.current < cue.time && currentTime >= cue.time;
344
+ if (!alreadyTriggered && crossedTime) {
345
+ triggeredRef.current.add(cueId);
346
+ cue.onTrigger();
347
+ }
348
+ }
349
+ lastTimeRef.current = currentTime;
350
+ }, [state.currentTime, state.duration, cuePoints, resetOnLoop]);
351
+ }
352
+ /**
353
+ * Hook to get the current video progress as a percentage (0-100).
354
+ * Useful for progress bars or time-based animations.
355
+ *
356
+ * @returns Progress percentage (0-100)
357
+ *
358
+ * @example
359
+ * ```tsx
360
+ * function ProgressBar() {
361
+ * const progress = useVideoProgress();
362
+ * return <div style={{ width: `${progress}%` }} className="h-1 bg-white" />;
363
+ * }
364
+ * ```
365
+ */
366
+ export function useVideoProgress() {
367
+ const { state } = useVideoState();
368
+ const { currentTime, duration } = state;
369
+ if (!duration || duration === 0)
370
+ return 0;
371
+ return Math.min(100, (currentTime / duration) * 100);
372
+ }
@@ -1,5 +1,5 @@
1
- export { VideoPlayer, useVideoState, } from './VideoPlayer';
2
- export type { VideoState, VideoControls, VideoContextValue, VideoPlayerProps, } from './VideoPlayer';
1
+ export { VideoPlayer, useVideoState, useCuePoint, useCuePoints, useVideoProgress, } from './VideoPlayer';
2
+ export type { VideoState, VideoControls, VideoContextValue, VideoPlayerProps, CuePoint, } from './VideoPlayer';
3
3
  export { Slideshow, useSlideshowState, } from './Slideshow';
4
4
  export type { SlideImage, SlideshowState, SlideshowControls, SlideshowContextValue, SlideshowProps, } from './Slideshow';
5
5
  export { OverlaySlot, FullOverlay, GradientOverlay, } from './OverlaySlot';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/overlay/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,SAAS,EACT,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/overlay/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,QAAQ,GACT,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,SAAS,EACT,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,eAAe,CAAC"}
@@ -1,5 +1,5 @@
1
1
  // Video player with HLS streaming support
2
- export { VideoPlayer, useVideoState, } from './VideoPlayer';
2
+ export { VideoPlayer, useVideoState, useCuePoint, useCuePoints, useVideoProgress, } from './VideoPlayer';
3
3
  // Image slideshow component
4
4
  export { Slideshow, useSlideshowState, } from './Slideshow';
5
5
  // Overlay positioning components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thewhateverapp/tile-sdk",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
4
4
  "description": "SDK for building interactive tiles on The Whatever App platform",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",