@scarlett-player/hls 0.1.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/dist/index.cjs +804 -0
- package/dist/index.d.cts +133 -0
- package/dist/index.d.ts +133 -0
- package/dist/index.js +767 -0
- package/package.json +62 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Plugin } from '@scarlett-player/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HLS Plugin Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** HLS plugin configuration options */
|
|
8
|
+
interface HLSPluginConfig {
|
|
9
|
+
/** Enable debug logging */
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
/** Auto start loading when source is set */
|
|
12
|
+
autoStartLoad?: boolean;
|
|
13
|
+
/** Start position in seconds (-1 for default) */
|
|
14
|
+
startPosition?: number;
|
|
15
|
+
/** Enable low latency mode for live streams */
|
|
16
|
+
lowLatencyMode?: boolean;
|
|
17
|
+
/** Max buffer length in seconds */
|
|
18
|
+
maxBufferLength?: number;
|
|
19
|
+
/** Max max buffer length in seconds */
|
|
20
|
+
maxMaxBufferLength?: number;
|
|
21
|
+
/** Back buffer length in seconds for DVR */
|
|
22
|
+
backBufferLength?: number;
|
|
23
|
+
/** Enable worker for hls.js (better performance) */
|
|
24
|
+
enableWorker?: boolean;
|
|
25
|
+
/** Max network error retries before giving up (default: 3) */
|
|
26
|
+
maxNetworkRetries?: number;
|
|
27
|
+
/** Max media error retries before giving up (default: 2) */
|
|
28
|
+
maxMediaRetries?: number;
|
|
29
|
+
/** Base retry delay in milliseconds (default: 1000) */
|
|
30
|
+
retryDelayMs?: number;
|
|
31
|
+
/** Exponential backoff multiplier (default: 2) */
|
|
32
|
+
retryBackoffFactor?: number;
|
|
33
|
+
/** Index signature for PluginConfig compatibility */
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** Quality level information */
|
|
37
|
+
interface HLSQualityLevel {
|
|
38
|
+
/** Level index in hls.js */
|
|
39
|
+
index: number;
|
|
40
|
+
/** Video width */
|
|
41
|
+
width: number;
|
|
42
|
+
/** Video height */
|
|
43
|
+
height: number;
|
|
44
|
+
/** Bitrate in bits per second */
|
|
45
|
+
bitrate: number;
|
|
46
|
+
/** Human-readable label (e.g., "1080p") */
|
|
47
|
+
label: string;
|
|
48
|
+
/** Codec info */
|
|
49
|
+
codec?: string;
|
|
50
|
+
}
|
|
51
|
+
/** HLS error types */
|
|
52
|
+
type HLSErrorType = 'network' | 'media' | 'mux' | 'other';
|
|
53
|
+
/** HLS error details */
|
|
54
|
+
interface HLSError {
|
|
55
|
+
type: HLSErrorType;
|
|
56
|
+
details: string;
|
|
57
|
+
fatal: boolean;
|
|
58
|
+
url?: string;
|
|
59
|
+
reason?: string;
|
|
60
|
+
response?: {
|
|
61
|
+
code: number;
|
|
62
|
+
text: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Live stream info */
|
|
66
|
+
interface HLSLiveInfo {
|
|
67
|
+
/** Whether stream is live */
|
|
68
|
+
isLive: boolean;
|
|
69
|
+
/** Edge latency in seconds */
|
|
70
|
+
latency: number;
|
|
71
|
+
/** Target latency for low latency mode */
|
|
72
|
+
targetLatency: number;
|
|
73
|
+
/** Drift from live edge */
|
|
74
|
+
drift: number;
|
|
75
|
+
}
|
|
76
|
+
/** HLS Plugin interface extending base Plugin */
|
|
77
|
+
interface IHLSPlugin extends Plugin<HLSPluginConfig> {
|
|
78
|
+
readonly id: 'hls-provider';
|
|
79
|
+
/** Check if this provider can play a source */
|
|
80
|
+
canPlay(src: string): boolean;
|
|
81
|
+
/** Load and play a source */
|
|
82
|
+
loadSource(src: string): Promise<void>;
|
|
83
|
+
/** Get current quality level index (-1 = auto) */
|
|
84
|
+
getCurrentLevel(): number;
|
|
85
|
+
/** Set quality level (-1 for auto) */
|
|
86
|
+
setLevel(index: number): void;
|
|
87
|
+
/** Get all available quality levels */
|
|
88
|
+
getLevels(): HLSQualityLevel[];
|
|
89
|
+
/** Get the raw hls.js instance (for advanced use) */
|
|
90
|
+
getHlsInstance(): unknown | null;
|
|
91
|
+
/** Check if using native HLS (Safari) */
|
|
92
|
+
isNativeHLS(): boolean;
|
|
93
|
+
/** Get live stream info */
|
|
94
|
+
getLiveInfo(): HLSLiveInfo | null;
|
|
95
|
+
/** Switch from hls.js to native HLS (for AirPlay) */
|
|
96
|
+
switchToNative(): Promise<void>;
|
|
97
|
+
/** Switch from native HLS back to hls.js */
|
|
98
|
+
switchToHlsJs(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* HLS Provider Plugin for Scarlett Player
|
|
103
|
+
*
|
|
104
|
+
* Provides HLS playback using hls.js or native HLS (Safari).
|
|
105
|
+
* Features:
|
|
106
|
+
* - Lazy loading of hls.js
|
|
107
|
+
* - Native HLS fallback for Safari
|
|
108
|
+
* - Quality level management
|
|
109
|
+
* - Error recovery
|
|
110
|
+
* - Live stream support
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Create an HLS Provider Plugin instance.
|
|
115
|
+
*
|
|
116
|
+
* @param config - Plugin configuration
|
|
117
|
+
* @returns HLS Plugin instance
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { createHLSPlugin } from '@scarlett-player/hls';
|
|
122
|
+
*
|
|
123
|
+
* const player = new ScarlettPlayer({
|
|
124
|
+
* container: document.getElementById('player'),
|
|
125
|
+
* plugins: [createHLSPlugin()],
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* await player.load('video.m3u8');
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function createHLSPlugin(config?: Partial<HLSPluginConfig>): IHLSPlugin;
|
|
132
|
+
|
|
133
|
+
export { type HLSError, type HLSLiveInfo, type HLSPluginConfig, type HLSQualityLevel, type IHLSPlugin, createHLSPlugin, createHLSPlugin as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Plugin } from '@scarlett-player/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HLS Plugin Types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** HLS plugin configuration options */
|
|
8
|
+
interface HLSPluginConfig {
|
|
9
|
+
/** Enable debug logging */
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
/** Auto start loading when source is set */
|
|
12
|
+
autoStartLoad?: boolean;
|
|
13
|
+
/** Start position in seconds (-1 for default) */
|
|
14
|
+
startPosition?: number;
|
|
15
|
+
/** Enable low latency mode for live streams */
|
|
16
|
+
lowLatencyMode?: boolean;
|
|
17
|
+
/** Max buffer length in seconds */
|
|
18
|
+
maxBufferLength?: number;
|
|
19
|
+
/** Max max buffer length in seconds */
|
|
20
|
+
maxMaxBufferLength?: number;
|
|
21
|
+
/** Back buffer length in seconds for DVR */
|
|
22
|
+
backBufferLength?: number;
|
|
23
|
+
/** Enable worker for hls.js (better performance) */
|
|
24
|
+
enableWorker?: boolean;
|
|
25
|
+
/** Max network error retries before giving up (default: 3) */
|
|
26
|
+
maxNetworkRetries?: number;
|
|
27
|
+
/** Max media error retries before giving up (default: 2) */
|
|
28
|
+
maxMediaRetries?: number;
|
|
29
|
+
/** Base retry delay in milliseconds (default: 1000) */
|
|
30
|
+
retryDelayMs?: number;
|
|
31
|
+
/** Exponential backoff multiplier (default: 2) */
|
|
32
|
+
retryBackoffFactor?: number;
|
|
33
|
+
/** Index signature for PluginConfig compatibility */
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** Quality level information */
|
|
37
|
+
interface HLSQualityLevel {
|
|
38
|
+
/** Level index in hls.js */
|
|
39
|
+
index: number;
|
|
40
|
+
/** Video width */
|
|
41
|
+
width: number;
|
|
42
|
+
/** Video height */
|
|
43
|
+
height: number;
|
|
44
|
+
/** Bitrate in bits per second */
|
|
45
|
+
bitrate: number;
|
|
46
|
+
/** Human-readable label (e.g., "1080p") */
|
|
47
|
+
label: string;
|
|
48
|
+
/** Codec info */
|
|
49
|
+
codec?: string;
|
|
50
|
+
}
|
|
51
|
+
/** HLS error types */
|
|
52
|
+
type HLSErrorType = 'network' | 'media' | 'mux' | 'other';
|
|
53
|
+
/** HLS error details */
|
|
54
|
+
interface HLSError {
|
|
55
|
+
type: HLSErrorType;
|
|
56
|
+
details: string;
|
|
57
|
+
fatal: boolean;
|
|
58
|
+
url?: string;
|
|
59
|
+
reason?: string;
|
|
60
|
+
response?: {
|
|
61
|
+
code: number;
|
|
62
|
+
text: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Live stream info */
|
|
66
|
+
interface HLSLiveInfo {
|
|
67
|
+
/** Whether stream is live */
|
|
68
|
+
isLive: boolean;
|
|
69
|
+
/** Edge latency in seconds */
|
|
70
|
+
latency: number;
|
|
71
|
+
/** Target latency for low latency mode */
|
|
72
|
+
targetLatency: number;
|
|
73
|
+
/** Drift from live edge */
|
|
74
|
+
drift: number;
|
|
75
|
+
}
|
|
76
|
+
/** HLS Plugin interface extending base Plugin */
|
|
77
|
+
interface IHLSPlugin extends Plugin<HLSPluginConfig> {
|
|
78
|
+
readonly id: 'hls-provider';
|
|
79
|
+
/** Check if this provider can play a source */
|
|
80
|
+
canPlay(src: string): boolean;
|
|
81
|
+
/** Load and play a source */
|
|
82
|
+
loadSource(src: string): Promise<void>;
|
|
83
|
+
/** Get current quality level index (-1 = auto) */
|
|
84
|
+
getCurrentLevel(): number;
|
|
85
|
+
/** Set quality level (-1 for auto) */
|
|
86
|
+
setLevel(index: number): void;
|
|
87
|
+
/** Get all available quality levels */
|
|
88
|
+
getLevels(): HLSQualityLevel[];
|
|
89
|
+
/** Get the raw hls.js instance (for advanced use) */
|
|
90
|
+
getHlsInstance(): unknown | null;
|
|
91
|
+
/** Check if using native HLS (Safari) */
|
|
92
|
+
isNativeHLS(): boolean;
|
|
93
|
+
/** Get live stream info */
|
|
94
|
+
getLiveInfo(): HLSLiveInfo | null;
|
|
95
|
+
/** Switch from hls.js to native HLS (for AirPlay) */
|
|
96
|
+
switchToNative(): Promise<void>;
|
|
97
|
+
/** Switch from native HLS back to hls.js */
|
|
98
|
+
switchToHlsJs(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* HLS Provider Plugin for Scarlett Player
|
|
103
|
+
*
|
|
104
|
+
* Provides HLS playback using hls.js or native HLS (Safari).
|
|
105
|
+
* Features:
|
|
106
|
+
* - Lazy loading of hls.js
|
|
107
|
+
* - Native HLS fallback for Safari
|
|
108
|
+
* - Quality level management
|
|
109
|
+
* - Error recovery
|
|
110
|
+
* - Live stream support
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Create an HLS Provider Plugin instance.
|
|
115
|
+
*
|
|
116
|
+
* @param config - Plugin configuration
|
|
117
|
+
* @returns HLS Plugin instance
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { createHLSPlugin } from '@scarlett-player/hls';
|
|
122
|
+
*
|
|
123
|
+
* const player = new ScarlettPlayer({
|
|
124
|
+
* container: document.getElementById('player'),
|
|
125
|
+
* plugins: [createHLSPlugin()],
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* await player.load('video.m3u8');
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function createHLSPlugin(config?: Partial<HLSPluginConfig>): IHLSPlugin;
|
|
132
|
+
|
|
133
|
+
export { type HLSError, type HLSLiveInfo, type HLSPluginConfig, type HLSQualityLevel, type IHLSPlugin, createHLSPlugin, createHLSPlugin as default };
|