oddysee-react 0.2.0-canary.2 → 0.2.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 +59 -0
- package/dist/index.cjs +33512 -2
- package/dist/index.d.cts +177 -1
- package/dist/index.d.ts +177 -1
- package/dist/index.js +33511 -3
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,181 @@
|
|
|
1
1
|
import { ChangeEvent, PointerEvent, MouseEvent, TouchEvent } from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
interface PlayerConfig {
|
|
4
|
+
network?: {
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
retryCount?: number;
|
|
8
|
+
};
|
|
9
|
+
audio?: {
|
|
10
|
+
crossfade?: boolean;
|
|
11
|
+
normalization?: boolean;
|
|
12
|
+
preload?: boolean;
|
|
13
|
+
volume?: number;
|
|
14
|
+
};
|
|
15
|
+
playback?: {
|
|
16
|
+
autoPlay?: boolean;
|
|
17
|
+
startTime?: number;
|
|
18
|
+
staleAfterMs?: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface SourceOptions {
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
startTime?: number;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
interface Track {
|
|
27
|
+
id: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
url: string;
|
|
30
|
+
duration?: number;
|
|
31
|
+
currentTime: number;
|
|
32
|
+
}
|
|
33
|
+
interface PlayerState {
|
|
34
|
+
track: Track | null;
|
|
35
|
+
currentTime: number;
|
|
36
|
+
duration: number | null;
|
|
37
|
+
volume: number;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
error: PlayerError | null;
|
|
40
|
+
readyState: number;
|
|
41
|
+
isPlaying: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface QualityLevel {
|
|
44
|
+
id: number;
|
|
45
|
+
name: string;
|
|
46
|
+
bitrate: number;
|
|
47
|
+
audioCodec?: string;
|
|
48
|
+
}
|
|
49
|
+
type PlayerEvent = 'play' | 'pause' | 'track-end' | 'error' | 'quality-change' | 'playlist-ready' | 'loadedmetadata' | 'timeupdate' | 'loading' | 'canplay';
|
|
50
|
+
interface PlayerEventMap$1 {
|
|
51
|
+
play: void;
|
|
52
|
+
pause: void;
|
|
53
|
+
'track-end': Track | null;
|
|
54
|
+
error: PlayerError;
|
|
55
|
+
'quality-change': QualityLevel;
|
|
56
|
+
'playlist-ready': void;
|
|
57
|
+
loadedmetadata: Track | null;
|
|
58
|
+
timeupdate: {
|
|
59
|
+
currentTime: number;
|
|
60
|
+
duration: number | null;
|
|
61
|
+
};
|
|
62
|
+
loading: void;
|
|
63
|
+
canplay: void;
|
|
64
|
+
}
|
|
65
|
+
interface PlayerError {
|
|
66
|
+
code: 'NETWORK_ERROR' | 'MEDIA_ERROR' | 'PLAYBACK_ERROR' | 'FORMAT_NOT_SUPPORTED' | 'UNKNOWN_ERROR';
|
|
67
|
+
message: string;
|
|
68
|
+
details?: any;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface HLSAudioPlayerInterface {
|
|
72
|
+
setSource(url: string, options?: SourceOptions): Promise<HLSAudioPlayer>;
|
|
73
|
+
getCurrentTrack(): Track | null;
|
|
74
|
+
on<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
75
|
+
off<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
76
|
+
play(): HLSAudioPlayer;
|
|
77
|
+
playAsync(): Promise<HLSAudioPlayer>;
|
|
78
|
+
pause(): HLSAudioPlayer;
|
|
79
|
+
setVolume(volume: number): HLSAudioPlayer;
|
|
80
|
+
beginSeek(): void;
|
|
81
|
+
updateSeek(time: number): void;
|
|
82
|
+
commitSeek(): void;
|
|
83
|
+
retry(count?: number, interval?: number): void;
|
|
84
|
+
getState(): PlayerState;
|
|
85
|
+
getAudioElement(): HTMLAudioElement;
|
|
86
|
+
loading: boolean;
|
|
87
|
+
readyState: number;
|
|
88
|
+
error: PlayerError | null;
|
|
89
|
+
destroy(): void;
|
|
90
|
+
}
|
|
91
|
+
declare class HLSAudioPlayer implements HLSAudioPlayerInterface {
|
|
92
|
+
private hls;
|
|
93
|
+
private audioElement;
|
|
94
|
+
private config;
|
|
95
|
+
private eventListeners;
|
|
96
|
+
private currentTrack?;
|
|
97
|
+
private _loading;
|
|
98
|
+
private _error;
|
|
99
|
+
private _isPlaying;
|
|
100
|
+
private isSeeking;
|
|
101
|
+
private seekPreviewTime;
|
|
102
|
+
private retryCount;
|
|
103
|
+
private retryInterval;
|
|
104
|
+
private hasPlayedOnce;
|
|
105
|
+
private lastPausedAt;
|
|
106
|
+
private lastVisibilityHiddenAt;
|
|
107
|
+
private staleMedia;
|
|
108
|
+
private staleAfterMs;
|
|
109
|
+
private resumeRequested;
|
|
110
|
+
private authRecoveryInFlight;
|
|
111
|
+
private lastAuthRecoveryAt;
|
|
112
|
+
private authRecoveryCooldownMs;
|
|
113
|
+
get loading(): boolean;
|
|
114
|
+
get readyState(): number;
|
|
115
|
+
get error(): PlayerError | null;
|
|
116
|
+
get isPlaying(): boolean;
|
|
117
|
+
constructor(config?: PlayerConfig);
|
|
118
|
+
beginSeek(): void;
|
|
119
|
+
updateSeek(time: number): void;
|
|
120
|
+
commitSeek(): Promise<void>;
|
|
121
|
+
retry(count?: number, interval?: number): void;
|
|
122
|
+
private mapConfigToHLS;
|
|
123
|
+
private setupHlsEvents;
|
|
124
|
+
private setupAudioEvents;
|
|
125
|
+
private setupLifecycleEvents;
|
|
126
|
+
private markActivity;
|
|
127
|
+
private getIdleDurationMs;
|
|
128
|
+
private shouldRefreshBeforeResume;
|
|
129
|
+
private refreshSourceForResume;
|
|
130
|
+
private extractResponseCode;
|
|
131
|
+
private shouldRecoverFromAuthError;
|
|
132
|
+
private handleAuthErrorRecovery;
|
|
133
|
+
private updateCurrentTrack;
|
|
134
|
+
private mapHlsError;
|
|
135
|
+
private normalizeHlsErrorData;
|
|
136
|
+
/**
|
|
137
|
+
* sets source of the player
|
|
138
|
+
* @param url
|
|
139
|
+
* @param options
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
setSource(url: string, options?: SourceOptions): Promise<HLSAudioPlayer>;
|
|
143
|
+
/**
|
|
144
|
+
* plays current source/track
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
play(): HLSAudioPlayer;
|
|
148
|
+
/**
|
|
149
|
+
* Plays the current source/track and returns a Promise so callers can
|
|
150
|
+
* await or chain then/catch (e.g. to handle autoplay errors explicitly).
|
|
151
|
+
*/
|
|
152
|
+
playAsync(): Promise<HLSAudioPlayer>;
|
|
153
|
+
/**
|
|
154
|
+
* Pauses the current source/track
|
|
155
|
+
* @returns
|
|
156
|
+
*/
|
|
157
|
+
pause(): HLSAudioPlayer;
|
|
158
|
+
setVolume(volume: number): HLSAudioPlayer;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the current value of the volume
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
163
|
+
getVolume(): number;
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* gets the whole state of the player
|
|
167
|
+
*/
|
|
168
|
+
getState(): PlayerState;
|
|
169
|
+
getAudioElement(): HTMLAudioElement;
|
|
170
|
+
getQualityLevels(): QualityLevel[];
|
|
171
|
+
setQuality(quality: number | string): void;
|
|
172
|
+
private getQualityName;
|
|
173
|
+
getCurrentTrack(): Track | null;
|
|
174
|
+
on<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
175
|
+
off<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
176
|
+
private emit;
|
|
177
|
+
destroy(): void;
|
|
178
|
+
}
|
|
3
179
|
|
|
4
180
|
type PlayerEventMap = {
|
|
5
181
|
play: void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,181 @@
|
|
|
1
1
|
import { ChangeEvent, PointerEvent, MouseEvent, TouchEvent } from 'react';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
interface PlayerConfig {
|
|
4
|
+
network?: {
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
timeout?: number;
|
|
7
|
+
retryCount?: number;
|
|
8
|
+
};
|
|
9
|
+
audio?: {
|
|
10
|
+
crossfade?: boolean;
|
|
11
|
+
normalization?: boolean;
|
|
12
|
+
preload?: boolean;
|
|
13
|
+
volume?: number;
|
|
14
|
+
};
|
|
15
|
+
playback?: {
|
|
16
|
+
autoPlay?: boolean;
|
|
17
|
+
startTime?: number;
|
|
18
|
+
staleAfterMs?: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface SourceOptions {
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
startTime?: number;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
interface Track {
|
|
27
|
+
id: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
url: string;
|
|
30
|
+
duration?: number;
|
|
31
|
+
currentTime: number;
|
|
32
|
+
}
|
|
33
|
+
interface PlayerState {
|
|
34
|
+
track: Track | null;
|
|
35
|
+
currentTime: number;
|
|
36
|
+
duration: number | null;
|
|
37
|
+
volume: number;
|
|
38
|
+
loading: boolean;
|
|
39
|
+
error: PlayerError | null;
|
|
40
|
+
readyState: number;
|
|
41
|
+
isPlaying: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface QualityLevel {
|
|
44
|
+
id: number;
|
|
45
|
+
name: string;
|
|
46
|
+
bitrate: number;
|
|
47
|
+
audioCodec?: string;
|
|
48
|
+
}
|
|
49
|
+
type PlayerEvent = 'play' | 'pause' | 'track-end' | 'error' | 'quality-change' | 'playlist-ready' | 'loadedmetadata' | 'timeupdate' | 'loading' | 'canplay';
|
|
50
|
+
interface PlayerEventMap$1 {
|
|
51
|
+
play: void;
|
|
52
|
+
pause: void;
|
|
53
|
+
'track-end': Track | null;
|
|
54
|
+
error: PlayerError;
|
|
55
|
+
'quality-change': QualityLevel;
|
|
56
|
+
'playlist-ready': void;
|
|
57
|
+
loadedmetadata: Track | null;
|
|
58
|
+
timeupdate: {
|
|
59
|
+
currentTime: number;
|
|
60
|
+
duration: number | null;
|
|
61
|
+
};
|
|
62
|
+
loading: void;
|
|
63
|
+
canplay: void;
|
|
64
|
+
}
|
|
65
|
+
interface PlayerError {
|
|
66
|
+
code: 'NETWORK_ERROR' | 'MEDIA_ERROR' | 'PLAYBACK_ERROR' | 'FORMAT_NOT_SUPPORTED' | 'UNKNOWN_ERROR';
|
|
67
|
+
message: string;
|
|
68
|
+
details?: any;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface HLSAudioPlayerInterface {
|
|
72
|
+
setSource(url: string, options?: SourceOptions): Promise<HLSAudioPlayer>;
|
|
73
|
+
getCurrentTrack(): Track | null;
|
|
74
|
+
on<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
75
|
+
off<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
76
|
+
play(): HLSAudioPlayer;
|
|
77
|
+
playAsync(): Promise<HLSAudioPlayer>;
|
|
78
|
+
pause(): HLSAudioPlayer;
|
|
79
|
+
setVolume(volume: number): HLSAudioPlayer;
|
|
80
|
+
beginSeek(): void;
|
|
81
|
+
updateSeek(time: number): void;
|
|
82
|
+
commitSeek(): void;
|
|
83
|
+
retry(count?: number, interval?: number): void;
|
|
84
|
+
getState(): PlayerState;
|
|
85
|
+
getAudioElement(): HTMLAudioElement;
|
|
86
|
+
loading: boolean;
|
|
87
|
+
readyState: number;
|
|
88
|
+
error: PlayerError | null;
|
|
89
|
+
destroy(): void;
|
|
90
|
+
}
|
|
91
|
+
declare class HLSAudioPlayer implements HLSAudioPlayerInterface {
|
|
92
|
+
private hls;
|
|
93
|
+
private audioElement;
|
|
94
|
+
private config;
|
|
95
|
+
private eventListeners;
|
|
96
|
+
private currentTrack?;
|
|
97
|
+
private _loading;
|
|
98
|
+
private _error;
|
|
99
|
+
private _isPlaying;
|
|
100
|
+
private isSeeking;
|
|
101
|
+
private seekPreviewTime;
|
|
102
|
+
private retryCount;
|
|
103
|
+
private retryInterval;
|
|
104
|
+
private hasPlayedOnce;
|
|
105
|
+
private lastPausedAt;
|
|
106
|
+
private lastVisibilityHiddenAt;
|
|
107
|
+
private staleMedia;
|
|
108
|
+
private staleAfterMs;
|
|
109
|
+
private resumeRequested;
|
|
110
|
+
private authRecoveryInFlight;
|
|
111
|
+
private lastAuthRecoveryAt;
|
|
112
|
+
private authRecoveryCooldownMs;
|
|
113
|
+
get loading(): boolean;
|
|
114
|
+
get readyState(): number;
|
|
115
|
+
get error(): PlayerError | null;
|
|
116
|
+
get isPlaying(): boolean;
|
|
117
|
+
constructor(config?: PlayerConfig);
|
|
118
|
+
beginSeek(): void;
|
|
119
|
+
updateSeek(time: number): void;
|
|
120
|
+
commitSeek(): Promise<void>;
|
|
121
|
+
retry(count?: number, interval?: number): void;
|
|
122
|
+
private mapConfigToHLS;
|
|
123
|
+
private setupHlsEvents;
|
|
124
|
+
private setupAudioEvents;
|
|
125
|
+
private setupLifecycleEvents;
|
|
126
|
+
private markActivity;
|
|
127
|
+
private getIdleDurationMs;
|
|
128
|
+
private shouldRefreshBeforeResume;
|
|
129
|
+
private refreshSourceForResume;
|
|
130
|
+
private extractResponseCode;
|
|
131
|
+
private shouldRecoverFromAuthError;
|
|
132
|
+
private handleAuthErrorRecovery;
|
|
133
|
+
private updateCurrentTrack;
|
|
134
|
+
private mapHlsError;
|
|
135
|
+
private normalizeHlsErrorData;
|
|
136
|
+
/**
|
|
137
|
+
* sets source of the player
|
|
138
|
+
* @param url
|
|
139
|
+
* @param options
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
setSource(url: string, options?: SourceOptions): Promise<HLSAudioPlayer>;
|
|
143
|
+
/**
|
|
144
|
+
* plays current source/track
|
|
145
|
+
* @returns
|
|
146
|
+
*/
|
|
147
|
+
play(): HLSAudioPlayer;
|
|
148
|
+
/**
|
|
149
|
+
* Plays the current source/track and returns a Promise so callers can
|
|
150
|
+
* await or chain then/catch (e.g. to handle autoplay errors explicitly).
|
|
151
|
+
*/
|
|
152
|
+
playAsync(): Promise<HLSAudioPlayer>;
|
|
153
|
+
/**
|
|
154
|
+
* Pauses the current source/track
|
|
155
|
+
* @returns
|
|
156
|
+
*/
|
|
157
|
+
pause(): HLSAudioPlayer;
|
|
158
|
+
setVolume(volume: number): HLSAudioPlayer;
|
|
159
|
+
/**
|
|
160
|
+
* Gets the current value of the volume
|
|
161
|
+
* @returns
|
|
162
|
+
*/
|
|
163
|
+
getVolume(): number;
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* gets the whole state of the player
|
|
167
|
+
*/
|
|
168
|
+
getState(): PlayerState;
|
|
169
|
+
getAudioElement(): HTMLAudioElement;
|
|
170
|
+
getQualityLevels(): QualityLevel[];
|
|
171
|
+
setQuality(quality: number | string): void;
|
|
172
|
+
private getQualityName;
|
|
173
|
+
getCurrentTrack(): Track | null;
|
|
174
|
+
on<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
175
|
+
off<K extends PlayerEvent>(event: K, callback: (data: PlayerEventMap$1[K]) => void): void;
|
|
176
|
+
private emit;
|
|
177
|
+
destroy(): void;
|
|
178
|
+
}
|
|
3
179
|
|
|
4
180
|
type PlayerEventMap = {
|
|
5
181
|
play: void;
|