@ct-player/embed 1.0.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.
package/README.md ADDED
@@ -0,0 +1,269 @@
1
+ # @ct-player/embed
2
+
3
+ Standalone embeddable interactive course player for `.ct` files. This package bundles all dependencies for easy integration into any React application.
4
+
5
+ ## Features
6
+
7
+ - **Full Playback** - Video/audio + synchronized code, terminal, whiteboard
8
+ - **Streaming Support** - HLS streaming with adaptive quality
9
+ - **Interactive Mode** - Pause and edit code in real-time
10
+ - **Embeddable** - Drop into any React 18/19 app
11
+ - **Themeable** - Light/dark modes with customization
12
+ - **Versioned** - Semantic versioning for easy updates
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @ct-player/embed
18
+ ```
19
+
20
+ ### Required Peer Dependencies
21
+
22
+ ```bash
23
+ npm install react react-dom lucide-react
24
+ ```
25
+
26
+ ### Optional Peer Dependencies
27
+
28
+ Install based on features you need:
29
+
30
+ ```bash
31
+ # For code editor panels
32
+ npm install @monaco-editor/react
33
+
34
+ # For whiteboard panels
35
+ npm install @excalidraw/excalidraw
36
+
37
+ # For PDF/document viewing
38
+ npm install react-pdf
39
+ ```
40
+
41
+ ## Quick Start
42
+
43
+ ### Basic Player
44
+
45
+ ```tsx
46
+ import { CoursePlayer } from '@ct-player/embed';
47
+ import '@ct-player/embed/styles.css';
48
+
49
+ function App() {
50
+ return (
51
+ <CoursePlayer
52
+ recordingUrl="https://cdn.example.com/course.ct"
53
+ theme="dark"
54
+ allowInteraction={true}
55
+ onComplete={() => console.log('Course completed!')}
56
+ />
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### Streaming Player (HLS/CDN)
62
+
63
+ ```tsx
64
+ import { StreamingCoursePlayer } from '@ct-player/embed';
65
+ import '@ct-player/embed/styles.css';
66
+
67
+ function App() {
68
+ return (
69
+ <StreamingCoursePlayer
70
+ manifestUrl="https://cdn.example.com/course/manifest.json"
71
+ theme="dark"
72
+ autoPlay={false}
73
+ onProgress={(time, duration) => {
74
+ console.log(`Progress: ${time}/${duration}`);
75
+ }}
76
+ />
77
+ );
78
+ }
79
+ ```
80
+
81
+ ## Props
82
+
83
+ ### CoursePlayer Props
84
+
85
+ #### Data Source (one required)
86
+
87
+ | Prop | Type | Description |
88
+ |------|------|-------------|
89
+ | `recording` | `CTRecording` | Pre-loaded recording data |
90
+ | `recordingUrl` | `string` | URL to a .ct file |
91
+ | `recordingId` | `string` | ID to fetch from API |
92
+
93
+ #### Appearance
94
+
95
+ | Prop | Type | Default | Description |
96
+ |------|------|---------|-------------|
97
+ | `theme` | `'light' \| 'dark' \| 'system'` | `'system'` | Color theme |
98
+ | `aspectRatio` | `'16:9' \| '4:3' \| 'auto'` | `'16:9'` | Player aspect ratio |
99
+ | `showToolbar` | `boolean` | `true` | Show playback controls |
100
+ | `showTimeline` | `boolean` | `true` | Show timeline |
101
+ | `showChapters` | `boolean` | `true` | Show chapter markers |
102
+
103
+ #### Behavior
104
+
105
+ | Prop | Type | Default | Description |
106
+ |------|------|---------|-------------|
107
+ | `autoPlay` | `boolean` | `false` | Start playing when loaded |
108
+ | `defaultSpeed` | `number` | `1.0` | Initial playback speed |
109
+ | `allowInteraction` | `boolean` | `true` | Allow code editing when paused |
110
+ | `allowFullscreen` | `boolean` | `true` | Allow fullscreen mode |
111
+
112
+ #### Callbacks
113
+
114
+ | Prop | Type | Description |
115
+ |------|------|-------------|
116
+ | `onReady` | `() => void` | Called when player is ready |
117
+ | `onPlay` | `() => void` | Called when playback starts |
118
+ | `onPause` | `() => void` | Called when playback pauses |
119
+ | `onProgress` | `(time, duration) => void` | Called on progress update |
120
+ | `onComplete` | `() => void` | Called when playback completes |
121
+ | `onError` | `(error) => void` | Called on error |
122
+
123
+ ### StreamingCoursePlayer Props
124
+
125
+ | Prop | Type | Description |
126
+ |------|------|-------------|
127
+ | `manifestUrl` | `string` | URL to streaming manifest |
128
+ | `theme` | `'light' \| 'dark'` | Color theme |
129
+ | `autoPlay` | `boolean` | Auto-start playback |
130
+ | `initialTime` | `number` | Start position in ms |
131
+
132
+ Plus all callback props from CoursePlayer.
133
+
134
+ ## Imperative API
135
+
136
+ Use a ref to control the player programmatically:
137
+
138
+ ```tsx
139
+ import { useRef } from 'react';
140
+ import { CoursePlayer, CoursePlayerRef } from '@ct-player/embed';
141
+
142
+ function App() {
143
+ const playerRef = useRef<CoursePlayerRef>(null);
144
+
145
+ return (
146
+ <>
147
+ <CoursePlayer ref={playerRef} recordingUrl="/course.ct" />
148
+ <button onClick={() => playerRef.current?.play()}>Play</button>
149
+ <button onClick={() => playerRef.current?.pause()}>Pause</button>
150
+ <button onClick={() => playerRef.current?.seek(30000)}>Skip to 30s</button>
151
+ <button onClick={() => playerRef.current?.setSpeed(1.5)}>1.5x Speed</button>
152
+ </>
153
+ );
154
+ }
155
+ ```
156
+
157
+ ### Available Ref Methods
158
+
159
+ | Method | Description |
160
+ |--------|-------------|
161
+ | `play()` | Start playback |
162
+ | `pause()` | Pause playback |
163
+ | `seek(timeMs)` | Seek to specific time |
164
+ | `setSpeed(speed)` | Set playback speed |
165
+ | `setVolume(volume)` | Set volume (0-1) |
166
+ | `toggleFullscreen()` | Toggle fullscreen |
167
+ | `getState()` | Get current playback state |
168
+
169
+ ## Hooks
170
+
171
+ For custom player implementations:
172
+
173
+ ```tsx
174
+ import { usePlayback, useStreamingPlayback, useRemoteStreamingPlayback } from '@ct-player/embed';
175
+
176
+ // Local .ct file playback
177
+ const { state, controls } = usePlayback({ recording });
178
+
179
+ // Chunked streaming
180
+ const { state, controls, metrics } = useStreamingPlayback(options);
181
+
182
+ // Remote CDN/HLS streaming
183
+ const { state, controls } = useRemoteStreamingPlayback(options);
184
+ ```
185
+
186
+ ## Utilities
187
+
188
+ ### Reading .ct Files
189
+
190
+ ```tsx
191
+ import { readCTFile } from '@ct-player/embed';
192
+
193
+ const arrayBuffer = await file.arrayBuffer();
194
+ const recording = await readCTFile(arrayBuffer, { loadAllEvents: true });
195
+ ```
196
+
197
+ ### HLS Support
198
+
199
+ ```tsx
200
+ import { isHlsSupported, hasNativeHlsSupport } from '@ct-player/embed';
201
+
202
+ if (isHlsSupported()) {
203
+ console.log('HLS playback available');
204
+ }
205
+ ```
206
+
207
+ ## Styling
208
+
209
+ The player comes with default styles. Import them in your app:
210
+
211
+ ```tsx
212
+ import '@ct-player/embed/styles.css';
213
+ ```
214
+
215
+ ### CSS Variables
216
+
217
+ Customize the theme using CSS variables:
218
+
219
+ ```css
220
+ :root {
221
+ --ct-player-bg: #1a1a1a;
222
+ --ct-player-text: #ffffff;
223
+ --ct-player-accent: #3b82f6;
224
+ --ct-player-border: #333333;
225
+ }
226
+ ```
227
+
228
+ ## Versioning
229
+
230
+ This package follows semantic versioning:
231
+
232
+ - **Patch** (1.0.x): Bug fixes, no breaking changes
233
+ - **Minor** (1.x.0): New features, backward compatible
234
+ - **Major** (x.0.0): Breaking changes
235
+
236
+ ### Updating
237
+
238
+ ```bash
239
+ # Update to latest patch
240
+ npm update @ct-player/embed
241
+
242
+ # Update to specific version
243
+ npm install @ct-player/embed@1.2.0
244
+
245
+ # Check for updates
246
+ npm outdated @ct-player/embed
247
+ ```
248
+
249
+ ## Browser Support
250
+
251
+ - Chrome 80+
252
+ - Firefox 75+
253
+ - Safari 14+
254
+ - Edge 80+
255
+
256
+ ## Bundle Size
257
+
258
+ The package bundles core dependencies for convenience:
259
+ - ~200KB minified (excluding peer dependencies)
260
+ - Tree-shakeable exports for custom implementations
261
+
262
+ ## License
263
+
264
+ MIT
265
+
266
+ ## Support
267
+
268
+ - [GitHub Issues](https://github.com/ct-courses/ct-player/issues)
269
+ - [Documentation](https://github.com/ct-courses/ct-player#readme)