@clipmux/player 0.1.1 → 0.1.2

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.
package/README.md CHANGED
@@ -1,178 +1,187 @@
1
1
  # @clipmux/player
2
2
 
3
- A drop-in React video player with built-in analytics, theming, and HLS support. Powered by [Vidstack](https://vidstack.io) — batteries included.
3
+ A beautiful, drop-in React video player engineered for the ClipMux video platform. Built on top of [Vidstack](https://vidstack.io) with baked-in analytics, HLS support, token-based security, chapters, and subtitles.
4
4
 
5
5
  ```bash
6
6
  npm install @clipmux/player
7
7
  ```
8
8
 
9
- ## Quick Start
9
+ ## Quick Start (Public Videos)
10
+
11
+ For public videos that don't require secure signed tokens, integration is a single line:
10
12
 
11
13
  ```tsx
12
14
  import { ClipMuxPlayer } from '@clipmux/player'
15
+ import '@clipmux/player/dist/index.css' // if applicable or if styles are extracted
13
16
 
14
17
  function App() {
15
18
  return <ClipMuxPlayer playbackId="your-video-id" />
16
19
  }
17
20
  ```
18
21
 
19
- That's it. No CSS imports, no extra dependencies — it just works.
20
-
21
- ## Usage
22
-
23
- ### Basic Playback
24
-
25
- ```tsx
26
- <ClipMuxPlayer playbackId="abc-123" />
22
+ That's it. It automatically resolves the HLS URL and begins securely sending playback analytics.
23
+
24
+ ---
25
+
26
+ ## Integrating with the ClipMux API (Private/Signed Videos)
27
+
28
+ For secure, private videos (the default), your application needs to authenticate the user, request a short-lived playback token from the ClipMux backend, and securely pass that to the player.
29
+
30
+ ### Step 1: Request a Playback Token (Your Backend)
31
+
32
+ Your backend should keep your ClipMux API key (`sk_live_...`) secret. When a user requests to watch a video, your backend calls the ClipMux API to get a temporary session.
33
+
34
+ ```typescript
35
+ // Example: Node.js / Next.js API Route
36
+ export async function GET(request, { params }) {
37
+ const videoId = params.id;
38
+ const viewerIp = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim();
39
+ const viewerUserAgent = request.headers.get('user-agent');
40
+
41
+ // 1. Verify your user has access to this video first!
42
+ // ...
43
+
44
+ // 2. Request a signed token from ClipMux
45
+ const clipmuxRes = await fetch(`https://api.clipmux.com/v1/video/${videoId}/playback-token`, {
46
+ method: 'POST',
47
+ headers: {
48
+ 'Authorization': `Bearer ${process.env.CLIPMUX_API_KEY}`,
49
+ 'Content-Type': 'application/json'
50
+ },
51
+ body: JSON.stringify({
52
+ expires_in: "2h",
53
+ viewer_ip: viewerIp, // Bind token to real viewer IP
54
+ viewer_user_agent: viewerUserAgent // Bind token to viewer User-Agent
55
+ })
56
+ });
57
+
58
+ const session = await clipmuxRes.json();
59
+
60
+ // session returns: { playback_url, token, expires_at, subtitle_url, chapters }
61
+ return Response.json(session);
62
+ }
27
63
  ```
28
64
 
29
- The player resolves the video URL automatically from the `playbackId`.
65
+ ### Step 2: Render the Player (Your Frontend)
30
66
 
31
- ### Signed / Private Videos
67
+ Fetch the session from your backend, and pass the properties directly into `<ClipMuxPlayer>`.
32
68
 
33
69
  ```tsx
34
- <ClipMuxPlayer
35
- playbackId="abc-123"
36
- token="eyJhbGciOiJIUzI1NiIs..."
37
- />
70
+ import { useState, useEffect } from 'react';
71
+ import { ClipMuxPlayer } from '@clipmux/player';
72
+
73
+ function LessonViewer({ videoId }) {
74
+ const [session, setSession] = useState(null);
75
+
76
+ useEffect(() => {
77
+ // Fetch the session from YOUR backend
78
+ fetch(`/api/videos/${videoId}/play`)
79
+ .then(res => res.json())
80
+ .then(data => setSession(data));
81
+ }, [videoId]);
82
+
83
+ if (!session) return <div>Loading...</div>;
84
+
85
+ return (
86
+ <ClipMuxPlayer
87
+ playbackId={videoId}
88
+ token={session.token} // Secure playback token
89
+ subtitles={session.subtitle_url} // Auto-loads AI generated subtitles
90
+ chapters={session.chapters} // Auto-generates chapter markers
91
+
92
+ // Optional customizations
93
+ title="Advanced React Patterns"
94
+ autoPlay={true}
95
+ theme={{ primaryColor: '#6366f1' }}
96
+ />
97
+ );
98
+ }
38
99
  ```
39
100
 
40
- The `token` is appended to the playback URL as a query parameter for secure delivery.
41
- When provided, the same token is also appended to `subtitles` and `poster` URLs (if set).
101
+ By providing the `token`, the player automatically appends it to all requested resources (video segments, subtitle tracks, and thumbnails), preventing unauthorized access.
42
102
 
43
- ### Custom Source (Escape Hatch)
103
+ ---
44
104
 
45
- If you use your own CDN or proxy, pass `src` directly. Keep `playbackId` so analytics still tracks correctly:
105
+ ## Advanced Features
46
106
 
47
- ```tsx
48
- <ClipMuxPlayer
49
- playbackId="abc-123"
50
- src="https://my-cdn.example.com/videos/abc-123/playlist.m3u8"
51
- />
52
- ```
53
-
54
- ### Full Example
107
+ ### Chapters & Subtitles
108
+ ClipMux can auto-generate AI subtitles and chapters. When fetching your playback token, the API will return `subtitle_url` and `chapters`. Passing these to the player automatically renders them using native WebVTT.
55
109
 
56
110
  ```tsx
57
111
  <ClipMuxPlayer
58
112
  playbackId="abc-123"
59
- envKey="pk_live_xxxxxxxx"
60
- token="eyJ..."
61
- title="Product Demo"
62
- poster="https://cdn.example.com/thumb.jpg"
63
- subtitles="https://cdn.example.com/subs-en.vtt"
113
+ subtitles="https://delivery.clipmux.com/.../subs.vtt"
64
114
  chapters={[
65
- { startTime: 0, endTime: 30, title: 'Intro' },
66
- { startTime: 30, endTime: 120, title: 'Features' },
67
- { startTime: 120, endTime: 180, title: 'Pricing' },
115
+ { startTime: 0, endTime: 60, title: 'Introduction' },
116
+ { startTime: 60, endTime: 300, title: 'Main Content' },
68
117
  ]}
69
- autoPlay
70
- muted
71
- theme={{ primaryColor: '#6366f1' }}
72
- onReady={() => console.log('Player loaded')}
73
- onEnded={() => console.log('Finished')}
74
- onError={(err) => console.error('Playback error:', err)}
75
118
  />
76
119
  ```
77
120
 
78
- ## Props
79
-
80
- | Prop | Type | Default | Description |
81
- |------|------|---------|-------------|
82
- | `playbackId` | `string` | — | ClipMux video ID. Resolves to the HLS URL automatically. |
83
- | `src` | `string` | — | Direct HLS/DASH URL. Overrides `playbackId` for playback. |
84
- | `envKey` | `string` | — | Tenant/environment key for multi-tenant analytics. |
85
- | `token` | `string` | — | Signed playback token for private content (auto-appended to playback, subtitles, and poster URLs). |
86
- | `title` | `string` | — | Video title displayed in the player UI. |
87
- | `poster` | `string` | — | Poster/thumbnail image URL. |
88
- | `subtitles` | `string` | — | VTT subtitle file URL. |
89
- | `chapters` | `Chapter[]` | — | Chapter markers (converted to VTT internally). |
90
- | `autoPlay` | `boolean` | `false` | Auto-play on load. |
91
- | `muted` | `boolean` | `false` | Start muted. |
92
- | `theme` | `object` | — | `{ primaryColor?, accentColor? }` — customize player colors. |
93
- | `className` | `string` | — | Additional CSS class on the player container. |
94
- | `style` | `CSSProperties` | — | Inline styles on the player container. |
95
- | `analyticsEndpoint` | `string \| false` | Production URL | Override the analytics beacon URL. Set to `false` to disable. |
96
- | `onReady` | `() => void` | — | Fired when the player is ready to play. |
97
- | `onError` | `(err: Error) => void` | — | Fired on playback error. |
98
- | `onEnded` | `() => void` | — | Fired when the video finishes. |
99
-
100
- ## Analytics
101
-
102
- The player sends playback analytics automatically:
103
-
104
- - **Events tracked**: `play`, `pause`, `seeking`, `seeked`, `ended`, `error`
105
- - **Heartbeat**: Every 10 seconds with accumulated `watchedDelta`
106
- - **Reliability**: Uses `navigator.sendBeacon` on page unload to guarantee delivery
107
- - **Session tracking**: A unique `sessionId` (UUID) is generated per player mount
108
-
109
- ### Disable Analytics
121
+ ### Theming
122
+ Customize the player to match your brand. `primaryColor` updates the timeline scrubber and main buttons.
110
123
 
111
124
  ```tsx
112
- <ClipMuxPlayer playbackId="abc-123" analyticsEndpoint={false} />
125
+ <ClipMuxPlayer
126
+ // ...
127
+ theme={{
128
+ primaryColor: '#6366f1', // Indigo
129
+ accentColor: '#f59e0b', // Amber
130
+ }}
131
+ />
113
132
  ```
114
133
 
115
- ### Custom Analytics Endpoint
134
+ ### Analytics
135
+ The player securely tracks real-time analytics (heartbeat, play/pause, seek, watch time) out of the box.
116
136
 
137
+ If you are using environments or multiple tenants, you can differentiate metrics by passing an environment key:
117
138
  ```tsx
118
- <ClipMuxPlayer
119
- playbackId="abc-123"
120
- analyticsEndpoint="https://your-proxy.example.com/v1/beacon"
121
- />
139
+ <ClipMuxPlayer playbackId="abc-123" envKey="pk_live_xxxx" />
122
140
  ```
123
141
 
124
- The endpoint receives `POST` requests with a JSON array of events:
125
-
126
- ```json
127
- [
128
- {
129
- "event": "heartbeat",
130
- "ts": "2026-02-16T10:30:00.000Z",
131
- "videoId": "abc-123",
132
- "sessionId": "550e8400-e29b-41d4-a716-446655440000",
133
- "envKey": "pk_live_xxx",
134
- "currentTime": 45.2,
135
- "duration": 180,
136
- "watchedDelta": 10.1
137
- }
138
- ]
142
+ To entirely disable analytics:
143
+ ```tsx
144
+ <ClipMuxPlayer playbackId="abc-123" analyticsEndpoint={false} />
139
145
  ```
140
146
 
141
- ## Theming
142
-
143
- Customize the player accent color using the `theme` prop:
147
+ ### Custom Sources (Escape Hatch)
148
+ If you are proxying the video through your own CDN, provide a `src` explicitly. `playbackId` is still strongly recommended so analytics continue to log properly against the video entity.
144
149
 
145
150
  ```tsx
146
151
  <ClipMuxPlayer
147
152
  playbackId="abc-123"
148
- theme={{
149
- primaryColor: '#6366f1', // Indigo
150
- accentColor: '#f59e0b', // Amber
151
- }}
153
+ src="https://my-custom-cdn.com/videos/abc-123/playlist.m3u8"
152
154
  />
153
155
  ```
154
156
 
155
- `primaryColor` maps to the Vidstack `--video-brand` CSS variable. You can also override styles via the `.clipmux-player` CSS class.
157
+ ---
156
158
 
157
- ## Chapters
159
+ ## Props Reference
158
160
 
159
- Pass chapter markers as an array — they're converted to WebVTT internally:
160
-
161
- ```tsx
162
- <ClipMuxPlayer
163
- playbackId="abc-123"
164
- chapters={[
165
- { startTime: 0, endTime: 60, title: 'Introduction' },
166
- { startTime: 60, endTime: 300, title: 'Main Content' },
167
- { startTime: 300, endTime: 360, title: 'Conclusion' },
168
- ]}
169
- />
170
- ```
161
+ | Prop | Type | Default | Description |
162
+ |------|------|---------|-------------|
163
+ | `playbackId` | `string` | — | **Required.** The ClipMux video ID. Automatically resolves the secure delivery URL. |
164
+ | `token` | `string` | — | Signed JWT for private content. Securely appended to video, subset, and poster requests. |
165
+ | `src` | `string` | — | Direct HLS/DASH URL. Overrides the auto-resolved URL from `playbackId`. |
166
+ | `envKey` | `string` | — | Tenant/environment key for multi-tenant analytics separation. |
167
+ | `title` | `string` | — | Video title displayed in the player UI heading. |
168
+ | `poster` | `string` | — | Custom poster/thumbnail image URL. |
169
+ | `subtitles` | `string` | — | VTT subtitle file URL (AI generated or custom). |
170
+ | `chapters` | `Chapter[]` | — | Array of chapter markers `{ startTime, endTime, title }`. |
171
+ | `autoPlay` | `boolean` | `false` | Start playback automatically when loaded. |
172
+ | `muted` | `boolean` | `false` | Start player muted. |
173
+ | `theme` | `object` | — | `{ primaryColor?, accentColor? }` to customize UI colors. |
174
+ | `className` | `string` | — | Additional CSS class for the player container. |
175
+ | `style` | `object` | — | Inline CSS properties. |
176
+ | `analyticsEndpoint` | `string \| false` | `default` | Custom analytics ingestion endpoint, or `false` to disable. |
177
+ | `onReady` | `() => void` | — | Fired when the video is loaded and ready to play. |
178
+ | `onError` | `(err) => void` | — | Fired on playback error. |
179
+ | `onEnded` | `() => void` | — | Fired when the video naturally finishes. |
171
180
 
172
181
  ## Requirements
173
182
 
174
183
  - **React** ≥ 18
175
- - No other peer dependencies — Vidstack is bundled inside the package.
184
+ - No other peer dependencies — Vidstack is fully bundled inside the package to avoid version conflicts.
176
185
 
177
186
  ## License
178
187
 
package/dist/index.cjs CHANGED
@@ -7600,6 +7600,9 @@ function sortVideoQualities(qualities, desc) {
7600
7600
  function compareVideoQualityAsc(a, b) {
7601
7601
  return a.height === b.height ? (a.bitrate ?? 0) - (b.bitrate ?? 0) : a.height - b.height;
7602
7602
  }
7603
+ function isHLSProvider(provider2) {
7604
+ return provider2?.$$PROVIDER_TYPE === "HLS";
7605
+ }
7603
7606
  function isHTMLAudioElement(element) {
7604
7607
  return !IS_SERVER3 && element instanceof HTMLAudioElement;
7605
7608
  }
@@ -12009,8 +12012,8 @@ var init_vidstack_D5Pzx_k5 = __esm({
12009
12012
  canGoogleCast.set(supported);
12010
12013
  }
12011
12014
  #watchFullscreenSupport() {
12012
- const { canFullscreen } = this.$state, supported = this.#fullscreen.supported || !!this.#$provider()?.fullscreen?.supported;
12013
- canFullscreen.set(supported);
12015
+ const { canFullscreen: canFullscreen2 } = this.$state, supported = this.#fullscreen.supported || !!this.#$provider()?.fullscreen?.supported;
12016
+ canFullscreen2.set(supported);
12014
12017
  }
12015
12018
  #watchPiPSupport() {
12016
12019
  const { canPictureInPicture } = this.$state, supported = !!this.#$provider()?.pictureInPicture?.supported;
@@ -14788,8 +14791,8 @@ var init_vidstack_D5Pzx_k5 = __esm({
14788
14791
  return fullscreen();
14789
14792
  }
14790
14793
  #isSupported() {
14791
- const { canFullscreen } = this.#media.$state;
14792
- return canFullscreen();
14794
+ const { canFullscreen: canFullscreen2 } = this.#media.$state;
14795
+ return canFullscreen2();
14793
14796
  }
14794
14797
  };
14795
14798
  MuteButton = class extends Component {
@@ -18162,6 +18165,7 @@ var init_vidstack_D5Pzx_k5 = __esm({
18162
18165
 
18163
18166
  // node_modules/.pnpm/@vidstack+react@1.12.13_@types+react@19.2.14_react@19.2.4/node_modules/@vidstack/react/prod/vidstack.js
18164
18167
  init_vidstack_D5Pzx_k5();
18168
+ init_vidstack_D5Pzx_k5();
18165
18169
  init_vidstack_CZgUA94N();
18166
18170
 
18167
18171
  // node_modules/.pnpm/@vidstack+react@1.12.13_@types+react@19.2.14_react@19.2.4/node_modules/@vidstack/react/prod/chunks/vidstack-DqtDbuaC.js
@@ -21141,6 +21145,15 @@ function ClipMuxPlayer({
21141
21145
  analytics.onError(e2?.message || "unknown");
21142
21146
  onError?.(new Error(e2?.message || "Playback error"));
21143
21147
  },
21148
+ onProviderChange: (provider2) => {
21149
+ if (isHLSProvider(provider2)) {
21150
+ provider2.config = {
21151
+ ...provider2.config,
21152
+ maxBufferLength: 30,
21153
+ maxMaxBufferLength: 30
21154
+ };
21155
+ }
21156
+ },
21144
21157
  onTimeUpdate: (detail) => {
21145
21158
  if (playerStateRef.current) {
21146
21159
  playerStateRef.current.currentTime = detail.currentTime;