@devix-technologies/react-gjirafa-vp-player 1.0.29 → 1.0.31-beta.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.
Files changed (43) hide show
  1. package/README.md +95 -707
  2. package/dist/index.d.ts +897 -9
  3. package/dist/react-gjirafa-vp-player.es.js +1183 -1289
  4. package/dist/react-gjirafa-vp-player.umd.js +12 -11
  5. package/package.json +8 -11
  6. package/dist/App.d.ts +0 -2
  7. package/dist/components/Feedback.d.ts +0 -25
  8. package/dist/components/VPPlayer/index.d.ts +0 -2
  9. package/dist/components/VPPlayer/ui/index.d.ts +0 -1
  10. package/dist/components/VPPlayer/ui/styled.d.ts +0 -42
  11. package/dist/config/index.d.ts +0 -1
  12. package/dist/config/vpPlayerConfig.d.ts +0 -9
  13. package/dist/constants/configs.d.ts +0 -22
  14. package/dist/constants/index.d.ts +0 -1
  15. package/dist/constants/storybook.d.ts +0 -9
  16. package/dist/constants/styles.d.ts +0 -11
  17. package/dist/constants/urls.d.ts +0 -18
  18. package/dist/constants/vpPlayer.d.ts +0 -47
  19. package/dist/contexts/VPPlayerContext.d.ts +0 -52
  20. package/dist/contexts/index.d.ts +0 -1
  21. package/dist/features/VPPlayer.d.ts +0 -41
  22. package/dist/features/stories/ads/Ads.stories.d.ts +0 -20
  23. package/dist/features/stories/context/Context.stories.d.ts +0 -10
  24. package/dist/features/stories/index.d.ts +0 -3
  25. package/dist/features/stories/playback/Playback.stories.d.ts +0 -38
  26. package/dist/fixtures/index.d.ts +0 -1
  27. package/dist/fixtures/playlist.d.ts +0 -11
  28. package/dist/hooks/index.d.ts +0 -4
  29. package/dist/hooks/useVPPlayerEvents.d.ts +0 -24
  30. package/dist/hooks/useVPPlayerLogic.d.ts +0 -22
  31. package/dist/hooks/useVPPlayerScript.d.ts +0 -13
  32. package/dist/hooks/useVideoData.d.ts +0 -19
  33. package/dist/interfaces/config.d.ts +0 -314
  34. package/dist/interfaces/index.d.ts +0 -3
  35. package/dist/interfaces/instance.d.ts +0 -73
  36. package/dist/interfaces/props.d.ts +0 -77
  37. package/dist/main.d.ts +0 -0
  38. package/dist/types/api.types.d.ts +0 -81
  39. package/dist/types/index.d.ts +0 -2
  40. package/dist/types/playerEvents.types.d.ts +0 -67
  41. package/dist/utils/index.d.ts +0 -2
  42. package/dist/utils/vpPlayerConfigBuilder.d.ts +0 -30
  43. package/dist/utils/vpPlayerUtils.d.ts +0 -8
package/README.md CHANGED
@@ -1,17 +1,20 @@
1
- # VP Player Component Documentation
1
+ # React Gjirafa VP Player
2
2
 
3
- The `VPPlayer` component is a React-based video player built using the VP Player library from `https://host.vpplayer.tech`.
3
+ A strict, lightweight React wrapper around the [Gjirafa VP Player SDK](https://vp.gjirafa.tech/documentation/docs/web-player/).
4
4
 
5
- It supports multiple ways to configure and play videos, including single files, playlists with direct files, single videos fetched via API, and playlists fetched via API. This document outlines the component's interface, configuration, and usage.
5
+ This package provides a clean interface for integrating the Gjirafa Player into React applications, adhering strictly to the official "Managed Script" implementation guide while adding necessary custom features for specific business needs (Reels mode, Analytics).
6
6
 
7
- ## Overview
7
+ ## Features
8
8
 
9
- The `VPPlayer` component dynamically loads the VP Player script (`vpplayer.js`) and initializes it with a configuration object. The configuration is built based on the provided props, which determine the source and type of video data to play. It supports **Horizontal (Standard)** and **Vertical (Reels)** modes, along with comprehensive analytics tracking.
9
+ - **Strict SDK Wrapping:** Uses the official `window.vpPlayer` / `window.vpVerticalPlayer` API.
10
+ - **Managed Script Loading:** Handles async script loading with caching and error handling.
11
+ - **Reels Mode:** Built-in "Overlay" UI for vertical short-form videos.
12
+ - **Native Events:** Bridges official SDK events (play, pause, quartiles) to React callbacks.
13
+ - **Custom Analytics:** Includes a custom "20 seconds watched" event (calculated from playback time).
14
+ - **Playlist Support:** Handles both Web Player and Vertical Player playlist configuration differences automatically.
10
15
 
11
16
  ## Installation
12
17
 
13
- To install the package, run:
14
-
15
18
  ```bash
16
19
  npm install @devix-technologies/react-gjirafa-vp-player
17
20
  # or
@@ -22,8 +25,6 @@ pnpm add @devix-technologies/react-gjirafa-vp-player
22
25
 
23
26
  ## Quick Start
24
27
 
25
- Here is a basic example of how to use the `VPPlayer` component in your React application:
26
-
27
28
  ```tsx
28
29
  import { VPPlayer } from "@devix-technologies/react-gjirafa-vp-player";
29
30
 
@@ -31,733 +32,120 @@ const App = () => {
31
32
  return (
32
33
  <div style={{ maxWidth: "800px", margin: "0 auto" }}>
33
34
  <VPPlayer
34
- playerId="my-unique-player-id"
35
+ playerId="unique-player-id"
35
36
  videoUrl="https://example.com/video.mp4"
36
37
  version="latest"
38
+ onPlayerPlay={() => console.log('Playing')}
37
39
  />
38
40
  </div>
39
41
  );
40
42
  };
41
-
42
- export default App;
43
- ```
44
-
45
- ## Source Files Structure
46
-
47
- ```
48
- ├── src/
49
- │ ├── components/
50
- │ │ └── VPPlayer/
51
- │ │ ├── index.ts
52
- │ │ └── ui/
53
- │ │ ├── index.ts
54
- │ │ ├── styled.tsx
55
- │ ├── config/
56
- │ │ ├── index.ts
57
- │ │ ├── vpPlayerConfig.ts
58
- │ ├── constants/
59
- │ │ ├── index.ts
60
- │ │ ├── vpPlayer.ts
61
- │ ├── contexts/
62
- │ │ ├── VPPlayerContext.tsx
63
- │ │ ├── index.ts
64
- │ ├── features/
65
- │ │ ├── VPPlayer.tsx
66
- │ │ ├── stories/
67
- │ │ │ ├── ads/
68
- │ │ │ │ ├── Ads.stories.tsx
69
- │ │ │ ├── context/
70
- │ │ │ │ ├── Context.stories.tsx
71
- │ │ │ ├── playback/
72
- │ │ │ │ ├── Playback.stories.tsx
73
- │ ├── fixtures/
74
- │ │ ├── index.ts
75
- │ │ ├── playlist.ts
76
- │ ├── hooks/
77
- │ │ ├── index.ts
78
- │ │ ├── useVPPlayerEvents.ts
79
- │ │ ├── useVPPlayerLogic.ts
80
- │ │ ├── useVPPlayerScript.ts
81
- │ │ ├── useVideoData.ts
82
- │ ├── interfaces/
83
- │ │ ├── config.ts
84
- │ │ ├── index.ts
85
- │ │ ├── instance.ts
86
- │ │ ├── props.ts
87
- │ │ ├── styles.ts
88
- │ ├── types/
89
- │ │ ├── api.types.ts
90
- │ │ ├── playerEvents.types.ts
91
- │ │ ├── index.ts
92
- │ ├── utils/
93
- │ │ ├── index.ts
94
- │ │ ├── vpPlayerConfigBuilder.ts
95
- │ │ ├── vpPlayerUtils.ts
96
- │ ├── App.css
97
- │ ├── App.tsx
98
- │ ├── index.css
99
- │ ├── main.tsx
100
- │ ├── vite-env.d.ts
101
- ```
102
-
103
- ## Interface
104
-
105
- The component accepts props defined by the `VPPlayerProps` interface:
106
-
107
- ```typescript
108
- interface VPPlayerProps {
109
- playerId: string; // Unique identifier for the player instance, might be random integer,
110
- but must be unique, for multiple VPPlayer instances use different values
111
- videoId?: string; // Unique identifier for the video or a placeholder
112
- version?: string | null; // Optional version e.g. "v2.1.1" of the VP Player script (defaults to 'latest')
113
- videoUrl?: string; // Direct URL to a single video file (e.g., .mp4, .m3u8)
114
- projectId?: string; // Project ID for API calls (used with videoId or playlistId)
115
- playlistId?: string; // Playlist ID for fetching a playlist from API
116
- config?: Partial<VPPlayerConfig>; // Optional partial configuration to override defaults
117
- isReels?: boolean; // Optional flag to enable Reels/iShorties mode (defaults to false)
118
- thumbnailUrl?: string; // Optional URL to a thumbnail image for Reels mode
119
- hiddenClasses?: string[]; // Optional array of CSS class names to hide specific player elements
120
- className?: string; // Optional CSS class name for additional styling of the player
121
- onClose, // Handler function triggered when the player is closed.
122
- isPlayerVisible, // Flag indicating whether the player is currently visible.
123
- onPlaylistData?: (videos: PlaylistItem[]) => void; // Optional callback that fires when playlist data is loaded
124
- onVideoStarted?: (videoData: CurrentVideoData) => void; // Optional callback that fires when a video starts playing
125
-
126
- // Analytics & Event Callbacks
127
- onPlayerStart?: (event: string) => void; // Fires when playback starts for the first time
128
- onPlayerPlay?: (event: string) => void; // Fires on subsequent play actions
129
- onPlayerPause?: (event: string) => void; // Fires when playback is paused
130
- onPlayerResume?: (event: string) => void; // Fires when playback is resumed
131
- onPlayerNext?: (event: string) => void; // Fires on next video click
132
- onPlayerPrevious?: (event: string) => void; // Fires on previous video click
133
- onPlayerEnd?: (event: string) => void; // Fires when video ends
134
- onPlayerProgressEvery10Seconds?: (event: string, currentPosition: number) => void; // Fires every 10s
135
- onPlayerProgressAt20Seconds?: (event: string, currentPosition: number) => void; // Fires specifically at 20s
136
- onPlayerQuartile25?: (event: string, currentPosition: number) => void; // Fires at 25% progress
137
- onPlayerQuartile50?: (event: string, currentPosition: number) => void; // Fires at 50% progress
138
- onPlayerQuartile75?: (event: string, currentPosition: number) => void; // Fires at 75% progress
139
- onPlayerEvent?: (event: string, currentPosition?: number) => void; // Universal callback for all events
140
- }
141
43
  ```
142
44
 
143
- ## Props Description
144
-
145
- ### **playerId: string**
146
-
147
- - Unique identifier for the player instance. Must be unique across multiple `VPPlayer` instances to avoid conflicts.
148
-
149
- ### **videoId?: string**
150
-
151
- - Optional identifier for a single video to fetch from the API. Used in conjunction with `projectId` for API-based video playback.
152
-
153
- ### **version?: string | null**
154
-
155
- - Optional version of the VP Player script (e.g., `"v2.1.1"`). Defaults to `"latest"` if not specified.
156
-
157
- ### **videoUrl?: string**
158
-
159
- - Optional direct URL to a video file (e.g., `.mp4`, `.m3u8`) for single-file playback without API involvement.
160
-
161
- ### **projectId?: string**
162
-
163
- - Optional project ID for API calls. Required when using `videoId` or `playlistId` to fetch video data from the API.
164
-
165
- ### **playlistId?: string**
166
-
167
- - Optional playlist ID for fetching a playlist from the API. Used with `projectId` to retrieve a dynamic playlist.
45
+ ## Usage Patterns
168
46
 
169
- ### **config?: Partial<VPPlayerConfig>**
47
+ ### 1. Standard Video Player (Horizontal)
48
+ Use for standard 16:9 content.
170
49
 
171
- - Optional partial configuration object to override the default `VPPlayerConfig`. Allows customization of player behavior and settings.
172
-
173
- ### **isReels?: boolean**
174
-
175
- - Optional flag to enable Reels/iShorties mode, optimizing the player for short vertical video playback (e.g., 9:16 aspect ratio). Defaults to `false`.
176
-
177
- ### **thumbnailUrl?: string**
178
-
179
- - Optional URL to a thumbnail image displayed in Reels mode before playback starts. Enhances the visual preview for short videos.
180
-
181
- ### **hiddenClasses?: string[]**
182
-
183
- - Optional array of CSS class names corresponding to player elements that should be hidden. Elements with these classes will have `display: none` applied, effectively removing them from the visible UI without affecting their underlying functionality (unless explicitly disabled). Useful for customizing the player's appearance by hiding unwanted controls.
184
- - **Example**: `["vp-icon-share", "vp-icon-fullscreen"]` hides the share and fullscreen buttons.
185
-
186
- ### **className?: string**
187
-
188
- - Optional CSS class name for additional styling of the player. This prop allows you to apply custom styles to the entire player component or its internal elements by targeting specific CSS classes (e.g., vp-play-pause, vp-control-bar). Styles must be defined in an external CSS file, and you can use !important to override default styles if needed. This provides flexibility to customize the player's appearance, such as changing colors, repositioning buttons, or adjusting layout.
189
- - **Example**: `"custom-player"` can be used to apply styles defined in an external CSS file like `.custom-player { border: 2px solid red; }` or `.custom-player .vp-play-pause { display: none; }`.
190
-
191
- ### **onClose?: => void;**
192
-
193
- - Optional handler function triggered when the player is closed. This callback is invoked when the user closes the player, typically via a close button or an overlay dismissal.
194
-
195
- ### **isPlayerVisible?: boolean;**
196
-
197
- - Optional flag indicating whether the player is currently visible. Controls the visibility of the player component, typically used to show or hide the player in a modal, overlay, or inline context.
198
-
199
- ### **onPlaylistData?: (videos: PlaylistItem[]) => void**
200
-
201
- - Optional callback function that fires when playlist data is successfully loaded from the API. This is useful for:
202
- - Getting a list of all videos in the playlist (including main and backup playlists)
203
- - Displaying a video list/menu in your UI
204
- - Pre-loading thumbnails or metadata
205
- - Building custom playlist navigation
206
- - **Parameters:**
207
- - `videos`: Array of `PlaylistItem` objects containing video metadata (title, hlsUrl, thumbnailUrl, duration, isBackupPlaylist, mediaId)
208
- - **When it fires:**
209
- - Once when playlist data is fetched from API (for playlists via `playlistId`)
210
- - **Example:**
211
- ```typescript
50
+ ```tsx
212
51
  <VPPlayer
213
- playerId="player"
214
- projectId="agmipnzb"
215
- playlistId="lzxikgjw"
216
- onPlaylistData={(videos) => {
217
- console.log('Playlist loaded:', videos.length, 'videos');
218
- console.log('Main videos:', videos.filter(v => !v.isBackupPlaylist).length);
219
- console.log('Backup videos:', videos.filter(v => v.isBackupPlaylist).length);
220
- // Update your UI with playlist data
221
- }}
52
+ playerId="main-player"
53
+ videoId="vjsnkiko" // API Video ID
54
+ projectId="agmipoaa" // Project ID
55
+ scriptUrl="https://host.vpplayer.tech/player/ptkzurly.js" // Your managed script URL
222
56
  />
223
57
  ```
224
58
 
225
- ### **onVideoStarted?: (videoData: CurrentVideoData) => void**
59
+ ### 2. Reels / Vertical Player
60
+ Use for TikTok-style vertical feeds. Enabling `isReels` adds the overlay UI.
226
61
 
227
- - Optional callback function that fires when a video starts playing. This provides real-time information about the currently playing video. Behavior differs between player types:
228
-
229
- **Vertical Player (Reels):**
230
- - Fires on scroll (swipe up/down) to navigate between videos
231
- - Fires on arrow button clicks (next/previous)
232
- - Returns basic metadata from the already-loaded playlist
233
-
234
- **Horizontal Player (Standard):**
235
- - Fires on Next/Previous button clicks
236
- - Fires when video ends and next video auto-plays
237
- - Fetches **complete metadata from API** (`https://host.vpplayer.tech/player/{playerId}/{videoId}.json`)
238
- - Returns comprehensive data including author, tags, publishDate, premium status, etc.
239
-
240
- - **Parameters:**
241
- - `videoData`: Object containing video metadata:
242
- - `videoId` - Video ID
243
- - `title` - Video title
244
- - `description` - Video description (HTML)
245
- - `file` / `hlsUrl` - Video stream URL
246
- - `thumbnailUrl` - Thumbnail image URL
247
- - `duration` - Video duration in seconds
248
- - `videoIndex` - Index in playlist (0-based)
249
- - `playlistVideoIndex` - VP Player playlist index
250
- - `isBackupPlaylist` - Whether video is from backup playlist
251
- - **Horizontal player additional fields:**
252
- - `publishDate` - Publication date (ISO format)
253
- - `projectId` - Project/entity ID
254
- - `premium` - Whether video is locked/premium
255
- - `author` - Video author name
256
- - `tags` - Array of video tags
257
-
258
- - **Use cases:**
259
- - **Analytics tracking**: Track video views, engagement, navigation patterns
260
- - **Custom UI updates**: Display current video info, progress indicators
261
- - **Content recommendations**: Use tags/author to suggest related content
262
- - **Monetization**: Check premium status, track ad opportunities
263
- - **Social features**: Display author info, enable sharing
264
-
265
- - **Example (Vertical Player):**
266
- ```typescript
62
+ ```tsx
267
63
  <VPPlayer
268
- playerId="vertical-player"
269
- projectId="agmipnzb"
270
- playlistId="lzxikgjw"
271
- scriptUrl="https://host.vpplayer.tech/vertical-player/rbqcdwznd.js"
64
+ playerId="reels-player"
272
65
  isReels={true}
273
- onVideoStarted={(videoData) => {
274
- console.log('Video changed:', videoData.title);
275
- console.log('Video index:', videoData.videoIndex);
276
- // Track analytics, update UI
277
- }}
278
- />
279
- ```
280
-
281
- - **Example (Horizontal Player with full metadata):**
282
- ```typescript
283
- <VPPlayer
284
- playerId="horizontal-player"
66
+ playlistId="lzxikgjw"
285
67
  projectId="agmipnzb"
286
- videoId="vjsnuhvm"
287
- scriptUrl="https://host.vpplayer.tech/player/ptkzurnx.js"
288
- onVideoStarted={(videoData) => {
289
- console.log('Video started:', videoData.title);
290
- console.log('Author:', videoData.author);
291
- console.log('Tags:', videoData.tags);
292
- console.log('Published:', videoData.publishDate);
293
- console.log('Premium:', videoData.premium);
294
-
295
- // Send to analytics
296
- analytics.track('video_started', {
297
- video_id: videoData.videoId,
298
- title: videoData.title,
299
- author: videoData.author,
300
- tags: videoData.tags
301
- });
302
- }}
303
- />
304
- ```
305
-
306
- ## Configuration
307
-
308
- ##### The player configuration is defined by the VPPlayerConfig interface, which is partially overridden by the config prop and dynamically built based on the input types.
309
-
310
- 1. Script Loading: Loads the VP Player script (https://host.vpplayer.tech/player/${PLAYER_VERSION}/vpplayer.js) asynchronously if not already present.
311
-
312
- 2. Player Setup: Once the script is loaded and the DOM element is rendered, the vpPlayer function is called with the element's ID and the final configuration.
313
-
314
- ## Supported Data Input Types
315
-
316
- ## Supported Data Input Types
317
-
318
- ##### The VPPlayer component supports multiple types of video data inputs, determined by the props provided:
319
-
320
- 1. **Single Video File**\
321
- Props: videoUrl\
322
- Behavior: Plays a single video directly from the provided URL.
323
-
324
- ##### Usage:
325
-
326
- ```bash
327
- <VPPlayer
328
- playerId="player-1" // Must be a unique string (e.g., "player-1", "123", etc.)
329
- version="latest"
330
- videoUrl="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
68
+ scriptUrl="https://host.vpplayer.tech/vertical-player/rbqcdwzlg.js"
69
+ thumbnailUrl="https://example.com/poster.jpg"
331
70
  />
332
71
  ```
333
72
 
334
- 2. **Playlist with Files**\
335
- Props: config with video.playlist\
336
- Behavior: Plays a playlist of videos defined statically in the config prop.
337
-
338
- ##### Usage:
339
-
340
- ```bash
341
- <VPPlayer
342
- playerId="player-2"
343
- version="latest"
344
- config={{
345
- projectId: 'vp-player-projectId', // optional placeholder
346
- video: {
347
- file: playlist.videos[0].file, // Initial video file, first in the queue
348
- playlist: playlist, // Pass the full playlist array object
349
- },
350
- }}
351
- />
352
- ```
353
-
354
- 3. **Single Video via API (VideoId)**\
355
- Props: projectId, videoId\
356
- Behavior: Fetches the playbackUrl from the API endpoint https://vp-api.gjirafa.tech/api/v2/projects/{projectId}/videos?search={videoId} and plays the video.
357
-
358
- ##### Usage:
359
-
360
- ```bash
361
- <VPPlayer
362
- playerId="player-3"
363
- version="latest"
364
- videoId="vjsnuxxx"
365
- projectId="agmipxxx"
366
- />
367
- ```
368
-
369
- 4. **Playlist via API (PlaylistId)**\
370
- Props: projectId, playlistId\
371
- Behavior: Fetches a playlist from the API endpoint https://vp-api.gjirafa.tech/api/projects/{projectId}/playlists/{playlistId}/videos and builds a playlist object dynamically.
372
-
373
- ##### Usage:
374
-
375
- ```bash
376
- <VPPlayer
377
- playerId="player-4"
378
- version="latest"
379
- projectId="agmipxxx"
380
- playlistId="lzxikxxx"
381
- />
382
- ```
383
-
384
- 5. **Example with `hiddenClasses` and `className`**\
385
-
386
- ##### Usage:
73
+ ### 3. Custom Playlist (Direct Files)
74
+ Pass a custom playlist structure. The wrapper automatically transforms this for the Vertical Player SDK if needed.
387
75
 
388
- ```bash
76
+ ```tsx
389
77
  <VPPlayer
390
- playerId="player-5"
391
- isReels={true}
392
- thumbnailUrl="https://images.pexels.com/videos/4678261/pexels-photo-4678261.jpeg?auto=compress&cs=tinysrgb&w=600"
393
- hiddenClasses={["vp-icon-share", "vp-icon-fullscreen"]} // Hides share and fullscreen buttons
394
- className="custom-player" // Defined class for custom styling
78
+ playerId="playlist-player"
395
79
  config={{
396
80
  video: {
397
81
  playlist: {
398
82
  state: true,
399
- playlistVideoIndex: 0,
400
83
  videos: [
401
- { videoId: "1", file: "https://videos.pexels.com/video-files/4678261/4678261-hd_1080_1920_25fps.mp4" },
402
- { videoId: "2", file: "https://videos.pexels.com/video-files/4678261/4678261-hd_1080_1920_25fps.mp4" },
403
- ],
404
- },
405
- },
84
+ { title: "Video 1", file: "https://.../1.mp4" },
85
+ { title: "Video 2", file: "https://.../2.mp4" }
86
+ ]
87
+ }
88
+ }
406
89
  }}
407
90
  />
408
-
409
- # e.g.
410
- /* Define custom styles in your CSS file */
411
- .custom-player {
412
- /* Your own styles here */
413
- }
414
- ```
415
-
416
- ## Video Tracking & Analytics
417
-
418
- The VPPlayer component provides two powerful callbacks for tracking video playback and playlist data:
419
-
420
- ### `onPlaylistData` - Playlist Data Callback
421
-
422
- Fires once when playlist is loaded. Useful for building custom UI or pre-loading data.
423
-
424
- ```typescript
425
- import { VPPlayer } from "@dvxx/vp-player";
426
- import { useState } from "react";
427
-
428
- const MyPlaylistComponent = () => {
429
- const [videos, setVideos] = useState([]);
430
-
431
- return (
432
- <>
433
- {/* Display video list */}
434
- <ul>
435
- {videos.map((video, idx) => (
436
- <li key={idx}>
437
- {video.title} {video.isBackupPlaylist && "(Backup)"}
438
- </li>
439
- ))}
440
- </ul>
441
-
442
- {/* Player with callback */}
443
- <VPPlayer
444
- playerId="my-playlist-player"
445
- projectId="agmipnzb"
446
- playlistId="lzxikgjw"
447
- onPlaylistData={(playlistVideos) => {
448
- setVideos(playlistVideos);
449
- console.log("Loaded videos:", playlistVideos.length);
450
- }}
451
- />
452
- </>
453
- );
454
- };
455
91
  ```
456
92
 
457
- ### `onVideoStarted` - Video Change Tracking
458
-
459
- Fires every time a video starts (scroll, click, auto-play). Perfect for analytics and real-time UI updates.
460
-
461
- **Vertical Player Example:**
462
-
463
- ```typescript
464
- <VPPlayer
465
- playerId="reels-player"
466
- projectId="agmipnzb"
467
- playlistId="lzxikgjw"
468
- scriptUrl="https://host.vpplayer.tech/vertical-player/rbqcdwznd.js"
469
- isReels={true}
470
- onVideoStarted={(videoData) => {
471
- // Fires on scroll or arrow navigation
472
- console.log("Now playing:", videoData.title);
473
- console.log("Video index:", videoData.videoIndex);
474
-
475
- // Send to analytics
476
- trackVideoView({
477
- videoId: videoData.videoId,
478
- index: videoData.videoIndex,
479
- isBackup: videoData.isBackupPlaylist
480
- });
481
- }}
482
- />
483
- ```
484
-
485
- **Horizontal Player Example (with full metadata):**
486
-
487
- ```typescript
488
- <VPPlayer
489
- playerId="standard-player"
490
- projectId="agmipnzb"
491
- videoId="vjsnuhvm"
492
- scriptUrl="https://host.vpplayer.tech/player/ptkzurnx.js"
493
- onVideoStarted={(videoData) => {
494
- // Fires on next/previous or auto-play
495
- // Full metadata fetched from API
496
- console.log({
497
- title: videoData.title,
498
- author: videoData.author,
499
- tags: videoData.tags,
500
- publishDate: videoData.publishDate,
501
- premium: videoData.premium,
502
- description: videoData.description
503
- });
504
-
505
- // Rich analytics tracking
506
- analytics.track("video_view", {
507
- video_id: videoData.videoId,
508
- video_title: videoData.title,
509
- author: videoData.author,
510
- tags: videoData.tags,
511
- is_premium: videoData.premium,
512
- project_id: videoData.projectId
513
- });
514
- }}
515
- />
516
- ```
517
-
518
- **Combined Example (both callbacks):**
519
-
520
- ```typescript
521
- import { VPPlayer } from "@dvxx/vp-player";
522
- import { useState } from "react";
523
-
524
- const AdvancedPlayerComponent = () => {
525
- const [playlistVideos, setPlaylistVideos] = useState([]);
526
- const [currentVideo, setCurrentVideo] = useState(null);
527
-
528
- return (
529
- <div>
530
- {/* Current video info */}
531
- {currentVideo && (
532
- <div className="video-info">
533
- <h3>{currentVideo.title}</h3>
534
- <p>Video {currentVideo.videoIndex + 1} of {playlistVideos.length}</p>
535
- {currentVideo.author && <p>By: {currentVideo.author}</p>}
536
- {currentVideo.tags && <p>Tags: {currentVideo.tags.join(", ")}</p>}
537
- </div>
538
- )}
539
-
540
- {/* Player */}
541
- <VPPlayer
542
- playerId="advanced-player"
543
- projectId="agmipnzb"
544
- playlistId="lzxikgjw"
545
- scriptUrl="https://host.vpplayer.tech/player/ptkzurnx.js"
546
- onPlaylistData={(videos) => {
547
- setPlaylistVideos(videos);
548
- console.log(`Playlist loaded: ${videos.length} videos`);
549
- }}
550
- onVideoStarted={(videoData) => {
551
- setCurrentVideo(videoData);
552
- console.log(`Playing video ${videoData.videoIndex + 1}`);
553
- }}
554
- />
555
-
556
- {/* Video playlist */}
557
- <div className="playlist">
558
- {playlistVideos.map((video, idx) => (
559
- <div
560
- key={idx}
561
- className={currentVideo?.videoIndex === idx ? "active" : ""}
562
- >
563
- {video.title}
564
- </div>
565
- ))}
566
- </div>
567
- </div>
568
- );
569
- };
570
- ```
571
-
572
- ### Playback Event Tracking (Analytics)
573
-
574
- Besides tracking playlist and video changes, `VPPlayer` offers granular callbacks for tracking player state and progress. This is ideal for sending data to analytics services (e.g., Google Analytics, Segment).
575
-
576
- You can use **specific callbacks** for each event type or a single **universal callback**.
577
-
578
- #### 1. Available Events
579
- The following events are tracked:
580
- - **State Events:** `player_start`, `player_play`, `player_pause`, `player_resume`, `player_end`, `player_next`, `player_previous`
581
- - **Progress Events:** `player_progress_every_10_seconds`, `player_progress_at_20_seconds`
582
- - **Quartile Events:** `player_quartile_25`, `player_quartile_50`, `player_quartile_75`
583
-
584
- *Note: Progress and Quartile events allow you to access the `currentPosition` (in seconds).*
585
-
586
- #### 2. Using Specific Callbacks
587
- Use this approach if you want to handle only specific events.
588
-
589
- ```typescript
590
- <VPPlayer
591
- // ... other props
592
- onPlayerStart={(event) => console.log("Started:", event)}
593
- onPlayerPause={(event) => console.log("Paused:", event)}
594
- onPlayerQuartile50={(event, time) => console.log("50% watched at:", time)}
595
- onPlayerEnd={(event) => console.log("Finished:", event)}
596
- />
597
- ```
598
-
599
- #### 3. Using Universal Callback (`onPlayerEvent`)
600
- Use this approach to route all events through a single function, which simplifies integration with analytics providers.
601
-
602
- ```typescript
603
- const handleAnalytics = (eventName: string, currentPosition?: number) => {
604
- // Example: Send to analytics layer
605
- analytics.track(eventName, {
606
- video_id: "12345",
607
- timestamp: currentPosition || 0,
608
- device: "desktop"
609
- });
610
-
611
- console.log(`[Analytics] ${eventName}`, currentPosition ? `Time: ${currentPosition}` : "");
612
- };
613
-
614
- <VPPlayer
615
- playerId="analytics-player"
616
- // ... other props
617
- onPlayerEvent={handleAnalytics}
618
- />
619
- ```
620
-
621
- ## Release Notes
622
-
623
- ### v1.0.27
624
- - **Fixes:**
625
- - Fixed `getCurrentVideoData()` to support **2 data sources**: config-based playlist, and single video
626
- - Fixed `onVideoStarted` callback to correctly return video data for config-based playlists
627
- - **Features:**
628
- - Improved video tracking for playlists passed directly via `config` prop
629
-
630
- ### v1.0.26
631
- - **Fixes:**
632
- - Fixed **config-based playlist indexing** for vertical players - `onVideoStarted` now correctly reports video index on scroll.
633
- - Fixed `getCurrentVideoData()` to properly handle playlists passed via `config.video.playlist.videos`.
634
- - Improved `vpPlayerConfigBuilder` to use correct initial video based on `playlistVideoIndex`.
635
- - **Refactor:**
636
- - Removed `fetchedPlaylist` dependency from `useVPPlayerLogic` - all playlist data now flows through config.
637
- - Cleaned up unused constants (`DEFAULT_PLAYLIST_ID` removed from exports).
638
-
639
- ### v1.0.25 (unpublished)
640
-
641
- ### v1.0.24
642
- - **Fixes:**
643
- - Fixed event tracking for vertical players with `isReels={false}`.
644
- - Unified event listener setup logic - detection now based on `scriptUrl` instead of `isReels` prop.
645
- - Fixed 400 Bad Request errors for horizontal player tracking by ensuring `projectId` is always included in config.
646
- - Re-added `ready` and `playlistItem` event listeners for horizontal player navigation.
647
- - **Features:**
648
- - Full metadata fetching now works for both vertical and horizontal players.
649
- - **Refactor:**
650
- - Changed `DEFAULT_PROJECT_ID` to generic value for better reusability.
651
- - Replaced `edge.vpplayer.tech` with `host.vpplayer.tech` for better performance.
652
-
653
- ### v1.0.23
654
- - **Features:**
655
- - Enhanced **vertical player analytics** with improved event tracking.
656
- - Added support for passing video arrays directly via `config.video.playlist.videos`.
657
- - **Fixes:**
658
- - Fixed duplicate event triggering in vertical player.
659
- - Improved `player_start` and `player_play` event logic for `player_next`/`player_previous` actions.
660
-
661
- ### v1.0.22
662
- - **New Features:**
663
- - Added comprehensive **Analytics Event Callbacks** (`onPlayerStart`, `onPlayerPlay`, `onPlayerPause`, `onPlayerEnd`, etc.).
664
- - Added **Universal `onPlayerEvent` callback** for simplified event tracking.
665
- - Added support for **Vertical Player analytics** including `player_next`/`player_previous` on scroll/swipe.
666
- - Added **Progress & Quartile events** (10s, 20s, 25%, 50%, 75%) with `currentPosition` data.
667
- - **Fixes:**
668
- - Fixed `videoId` configuration issue in VP Player tracking causing 400 errors.
669
- - Refined event logic to prevent duplicate events (e.g., `player_pause` during scroll/click).
670
-
671
- ### v1.0.21
672
- - **Fixes:**
673
- - Fixed vertical fullscreen video layout to rely on `aspect-ratio`.
674
- - Cleaned up unused variables in Storybook examples.
675
-
676
- ### v1.0.20
677
- - **Features:**
678
- - Added full metadata API fetch for **Vertical Player** (`onVideoStarted` now returns more comprehensive data).
679
-
680
- ### v1.0.19
681
- - **Features:**
682
- - Added full metadata support for **Horizontal Player**.
683
- - Introduced `onVideoStarted` callback for tracking video changes and retrieving metadata (title, author, tags, premium status, etc.).
684
- - **Documentation:**
685
- - Updated documentation to reflect new metadata capabilities.
686
-
687
- ### v1.0.18
688
- - **Features:**
689
- - Added `onPlaylistData` callback prop to access the full playlist structure (videos, backup status, etc.).
690
-
691
- ### v1.0.17
692
- - **Styles:**
693
- - Adjusted vertical player wrapper sizing for better layout consistency.
694
-
695
- ### v1.0.16
696
- - **Styles:**
697
- - Adjusted player container border radius overrides.
698
-
699
- ### v1.0.15
700
- - **Styles:**
701
- - Removed default rounded corners and borders from VP Player to allow easier custom styling.
702
-
703
- ### v1.0.14
704
- - **Features:**
705
- - Added support for **backup playlist videos** handling.
706
-
707
- ### v1.0.13
708
- - **Fixes:**
709
- - Fixed video ID indexing issue in sliced playlists for vertical player.
710
-
711
- ### v1.0.12
712
- - **Refactor:**
713
- - Reverted to original playlist configuration logic for better stability.
714
-
715
- ### v1.0.11
716
- - **Fixes:**
717
- - Fixed logic regarding the removal of the first video from the playlist.
718
-
719
- ### v1.0.10
720
- - **Features:**
721
- - Added TypeScript interfaces for tracks and `showCaptions`.
722
- - **Fixes:**
723
- - Fixed video indexing and thumbnail display issues in vertical player.
724
-
725
- ### v1.0.9
726
- - **Fixes:**
727
- - Ensure title and thumbnail are correctly applied to the first video in the playlist configuration.
728
-
729
- ### v1.0.8
730
- - **Features:**
731
- - Improved player configuration builder.
732
- - **Fixes:**
733
- - Fixed playlist video index bug.
734
- - Added functionality to start playlist from a specific index.
735
-
736
- ### v1.0.7
737
- - **Fixes:**
738
- - Handled timeout issues in vertical player.
739
- - Resolved all linting and TypeScript errors.
740
-
741
- ### v1.0.6
742
- - **Fixes:**
743
- - Fixed TypeScript build errors.
744
-
745
- ### v1.0.5
746
- - **Fixes:**
747
- - Fixed vertical player issue on page refresh.
748
- - Removed unnecessary type assertions.
749
-
750
- ### v1.0.4
751
- - **Fixes:**
752
- - Improved handling of vertical player video changes.
753
-
754
- ### v1.0.0 - v1.0.3
755
- - **Initial Release:**
756
- - Core `VPPlayer` component with support for:
757
- - Single video file playback.
758
- - Playlist playback (file-based and API-based).
759
- - Single video API fetching.
760
- - Reels/Vertical mode.
761
- - Added `useVPPlayerScript` and `useVideoData` hooks with retry and caching logic.
762
- - Unified error handling and configuration building.
763
- - Added Storybook examples and comprehensive documentation.
93
+ ## Architecture & Best Practices
94
+
95
+ This wrapper allows you to follow the "Green Field" approach—treating the player as a black box that just works.
96
+
97
+ ### 1. Controlled by Props, Powered by SDK
98
+ We do **not** expose the internal player instance via `ref`. All interaction should happen via:
99
+ - **Props:** To configure the player (`videoUrl`, `config`).
100
+ - **Callbacks:** To react to state changes (`onPlayerPlay`, `onVideoStarted`).
101
+
102
+ ### 2. Event Handling
103
+ We map native SDK events directly to React props.
104
+ - **Do not** set up your own event listeners using `window.vpPlayer().on(...)`.
105
+ - **Use the provided callbacks:**
106
+ - `onPlayerStart`, `onPlayerPlay`, `onPlayerPause`, `onPlayerEnd`
107
+ - `onPlayerProgressEvery10Seconds` (10s interval)
108
+ - `onPlayerProgressAt20Seconds` (Custom 20s milestone)
109
+ - `onPlayerQuartile25/50/75`
110
+
111
+ ### 3. Vertical Player Configuration
112
+ The Vertical Player SDK has a different configuration schema than the Web Player.
113
+ - **Web Player:** Accepts standard playlist object.
114
+ - **Vertical Player:** Requires `video.file` to be set even for playlists.
115
+ - **Solution:** This package's `vpPlayerConfigBuilder` handles this transformation automatically. You can pass the same config structure to both, and the builder will adapt it.
116
+
117
+ ## Custom Custom Functionality
118
+
119
+ ### "Reels" Overlay
120
+ When `isReels={true}`:
121
+ 1. The player renders a thumbnail first.
122
+ 2. Clicking the thumbnail opens the full-screen overlay.
123
+ 3. The player instance is initialized only when needed (or preloaded if configured).
124
+
125
+ ### "20 Seconds Watched" Event
126
+ The Gjirafa SDK does not have a native "watched for 20 seconds" event.
127
+ - **Implementation:** We listen to the native `time` event.
128
+ - **Logic:** When `currentTime >= 20`, we fire `onPlayerProgressAt20Seconds` once per video session.
129
+
130
+ ## Props Reference
131
+
132
+ | Prop | Type | Description |
133
+ |------|------|-------------|
134
+ | `playerId` | `string` | **Required.** Unique DOM ID for the player container. |
135
+ | `scriptUrl` | `string` | **Recommended.** The full URL to your Gjirafa managed script. |
136
+ | `videoId` | `string` | ID of the video to fetch from Gjirafa API. |
137
+ | `videoUrl` | `string` | Direct URL to a video file (mp4/m3u8). |
138
+ | `projectId` | `string` | Required if using `videoId` or `playlistId`. |
139
+ | `playlistId` | `string` | ID of the playlist to fetch from Gjirafa API. |
140
+ | `isReels` | `boolean` | Enables Vertical/Reels UI mode with overlay. |
141
+ | `config` | `object` | Deep overrides for the player configuration object. |
142
+ | `onPlayerEvent` | `func` | Universal callback for all analytics events. |
143
+
144
+ ## Migration Guide
145
+
146
+ If refactoring an existing integration to use this package:
147
+
148
+ 1. **Remove Old Script Tags:** Ensure `vpplayer.js` is not loaded globally in your `index.html`. This package handles loading.
149
+ 2. **Remove Custom State:** Delete any local state tracking `isPlaying`, `currentTime`, etc. Rely on the player's internal state and callbacks.
150
+ 3. **Simplify Config:** Stop manually constructing complex config objects. Pass `videoId`, `playlistId`, or `videoUrl` directly as props.
151
+ 4. **Use Callbacks:** Replace custom `setInterval` analytics trackers with `onPlayerProgressEvery10Seconds` and `onPlayerQuartile...` props.