@connectedxm/stream-player 0.0.1
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 +154 -0
- package/dist/index.es.js +22565 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/main.d.ts +0 -0
- package/dist/src/Example.d.ts +2 -0
- package/dist/src/StreamControls.d.ts +26 -0
- package/dist/src/StreamPlayer.d.ts +3 -0
- package/dist/src/hooks/useGetStreamLifecycle.d.ts +30 -0
- package/dist/src/hooks/useStreamPlayer.d.ts +30 -0
- package/dist/src/interfaces.d.ts +18 -0
- package/dist/src/utilities/GetLivestreamUrl.d.ts +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @connectedxm/stream-player
|
|
2
|
+
|
|
3
|
+
A React component for playing HLS live streams from Cloudflare Stream with built-in controls, quality selection, and multi-language support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎬 **HLS Playback** — Powered by [hls.js](https://github.com/video-dev/hls.js) with optimized defaults for live streaming
|
|
8
|
+
- 🌐 **Multi-language Streams** — Switch between multiple stream inputs (e.g., different audio languages)
|
|
9
|
+
- 📺 **Adaptive Quality** — Automatic bitrate adaptation with manual quality override
|
|
10
|
+
- 🎛️ **Built-in Controls** — Play/pause, volume, quality selector, language selector, and fullscreen
|
|
11
|
+
- 🔄 **Auto-reconnect** — Automatically reloads when a stream comes back online
|
|
12
|
+
- 📱 **Responsive** — Works across desktop and mobile browsers
|
|
13
|
+
- 🎨 **Styled with Tailwind** — Modern, customizable UI
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @connectedxm/stream-player
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- React 19+
|
|
24
|
+
- A Cloudflare Stream account with live input(s)
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { StreamPlayer } from "@connectedxm/stream-player";
|
|
30
|
+
import "@connectedxm/stream-player/styles.css";
|
|
31
|
+
|
|
32
|
+
const CLOUDFLARE_STREAM_DOMAIN = "customer-xxxxx.cloudflarestream.com";
|
|
33
|
+
|
|
34
|
+
const streamInputs = [
|
|
35
|
+
{
|
|
36
|
+
id: "1",
|
|
37
|
+
name: "English",
|
|
38
|
+
cloudflareId: "your-cloudflare-stream-id",
|
|
39
|
+
locale: "en",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "2",
|
|
43
|
+
name: "Spanish",
|
|
44
|
+
cloudflareId: "your-spanish-stream-id",
|
|
45
|
+
locale: "es",
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
function App() {
|
|
50
|
+
return (
|
|
51
|
+
<div className="w-full aspect-video">
|
|
52
|
+
<StreamPlayer
|
|
53
|
+
streamInputs={streamInputs}
|
|
54
|
+
cloudflareStreamDomain={CLOUDFLARE_STREAM_DOMAIN}
|
|
55
|
+
preferredLocale="en"
|
|
56
|
+
onError={(error) => console.error("Stream error:", error)}
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Props
|
|
64
|
+
|
|
65
|
+
### `StreamPlayerProps`
|
|
66
|
+
|
|
67
|
+
| Prop | Type | Required | Description |
|
|
68
|
+
| ------------------------ | ------------------------------ | -------- | --------------------------------------------- |
|
|
69
|
+
| `streamInputs` | `BaseStreamInput[]` | ✅ | Array of stream inputs to play |
|
|
70
|
+
| `cloudflareStreamDomain` | `string` | ✅ | Your Cloudflare Stream customer subdomain |
|
|
71
|
+
| `preferredLocale` | `string` | ❌ | Preferred locale for initial stream selection |
|
|
72
|
+
| `onError` | `(error: StreamError) => void` | ❌ | Callback when a stream error occurs |
|
|
73
|
+
| `hlsConfig` | `Partial<Hls.Config>` | ❌ | Custom hls.js configuration options |
|
|
74
|
+
|
|
75
|
+
### `BaseStreamInput`
|
|
76
|
+
|
|
77
|
+
| Property | Type | Required | Description |
|
|
78
|
+
| -------------- | -------- | -------- | ----------------------------------------- |
|
|
79
|
+
| `id` | `string` | ✅ | Unique identifier for the stream input |
|
|
80
|
+
| `name` | `string` | ✅ | Display name (shown in language selector) |
|
|
81
|
+
| `cloudflareId` | `string` | ✅ | Cloudflare Stream video/live input ID |
|
|
82
|
+
| `locale` | `string` | ❌ | Locale code (e.g., "en", "es") |
|
|
83
|
+
|
|
84
|
+
## Hooks
|
|
85
|
+
|
|
86
|
+
### `useStreamPlayer`
|
|
87
|
+
|
|
88
|
+
For advanced use cases, you can use the underlying hook directly to build custom player UIs:
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { useStreamPlayer } from "@connectedxm/stream-player";
|
|
92
|
+
|
|
93
|
+
const {
|
|
94
|
+
isLive,
|
|
95
|
+
hasError,
|
|
96
|
+
playing,
|
|
97
|
+
volume,
|
|
98
|
+
muted,
|
|
99
|
+
qualities,
|
|
100
|
+
currentQuality,
|
|
101
|
+
handlePlayPause,
|
|
102
|
+
handleVolumeChange,
|
|
103
|
+
handleMuteToggle,
|
|
104
|
+
handleQualityChange,
|
|
105
|
+
} = useStreamPlayer({
|
|
106
|
+
cloudflareId: "your-stream-id",
|
|
107
|
+
cloudflareStreamDomain: "customer-xxxxx.cloudflarestream.com",
|
|
108
|
+
videoRef: videoRef,
|
|
109
|
+
onError: (error) => console.error(error),
|
|
110
|
+
hlsConfig: {},
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## HLS Configuration
|
|
115
|
+
|
|
116
|
+
The player comes with sensible defaults optimized for live streaming:
|
|
117
|
+
|
|
118
|
+
- **Buffer**: 60s max buffer, 15s back buffer
|
|
119
|
+
- **Latency**: 8s live sync, 20s max latency before seeking to live
|
|
120
|
+
- **ABR**: Aggressive downgrade (0.8), cautious upgrade (0.2)
|
|
121
|
+
- **Resilience**: 6 retry attempts, 20s timeouts
|
|
122
|
+
|
|
123
|
+
You can override any hls.js config option via the `hlsConfig` prop:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
<StreamPlayer
|
|
127
|
+
streamInputs={inputs}
|
|
128
|
+
cloudflareStreamDomain={domain}
|
|
129
|
+
hlsConfig={{
|
|
130
|
+
lowLatencyMode: true,
|
|
131
|
+
liveSyncDuration: 3,
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Development
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# Install dependencies
|
|
140
|
+
npm install
|
|
141
|
+
|
|
142
|
+
# Start dev server
|
|
143
|
+
npm run dev
|
|
144
|
+
|
|
145
|
+
# Build library
|
|
146
|
+
npm run build
|
|
147
|
+
|
|
148
|
+
# Run tests
|
|
149
|
+
npm test
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|