feat: apply phase1 DX cleanup for private registry
This commit is contained in:
+17
-15
@@ -5,6 +5,7 @@
|
||||
|
||||
import type { AudioTrack, VideoQuality, SubtitleTrack } from '../types'
|
||||
import { getTranslations, detectBrowserLanguage } from '../i18n'
|
||||
import { logger } from './logger'
|
||||
|
||||
// Re-export control functions for backward compatibility
|
||||
export { setHlsQualityLevel, setHlsAudioTrack } from './hlsControl'
|
||||
@@ -47,20 +48,20 @@ const loadHlsFromCDN = (): Promise<any> => {
|
||||
*/
|
||||
export const loadHls = async (): Promise<any> => {
|
||||
try {
|
||||
console.log('[HLS Loader] Attempting to load from npm package...')
|
||||
logger.log('[HLS Loader] Attempting to load from npm package...')
|
||||
// Try loading from npm package first
|
||||
const hlsModule = await import('hls.js')
|
||||
console.log('[HLS Loader] Successfully loaded from npm package')
|
||||
logger.log('[HLS Loader] Successfully loaded from npm package')
|
||||
return hlsModule.default
|
||||
} catch (npmError) {
|
||||
console.warn('[HLS Loader] Failed to load from npm, trying CDN...', npmError)
|
||||
logger.warn('[HLS Loader] Failed to load from npm, trying CDN...', npmError)
|
||||
try {
|
||||
// Fallback to CDN
|
||||
const Hls = await loadHlsFromCDN()
|
||||
console.log('[HLS Loader] Successfully loaded from CDN')
|
||||
logger.log('[HLS Loader] Successfully loaded from CDN')
|
||||
return Hls
|
||||
} catch (cdnError) {
|
||||
console.error('[HLS Loader] Failed to load from CDN:', cdnError)
|
||||
logger.error('[HLS Loader] Failed to load from CDN:', cdnError)
|
||||
throw new Error('Unable to load HLS.js library. HLS streaming is not available.')
|
||||
}
|
||||
}
|
||||
@@ -87,17 +88,17 @@ export const hasNativeHlsSupport = (): boolean => {
|
||||
export const getHlsAudioTracks = (hls: any): AudioTrack[] => {
|
||||
try {
|
||||
if (!hls) {
|
||||
console.warn('[HLS Loader] getHlsAudioTracks: No HLS instance provided')
|
||||
logger.warn('[HLS Loader] getHlsAudioTracks: No HLS instance provided')
|
||||
return []
|
||||
}
|
||||
|
||||
// Check if audioTracks property exists
|
||||
if (!hls.audioTracks || !Array.isArray(hls.audioTracks)) {
|
||||
console.warn('[HLS Loader] getHlsAudioTracks: No audioTracks array found on HLS instance')
|
||||
logger.warn('[HLS Loader] getHlsAudioTracks: No audioTracks array found on HLS instance')
|
||||
return []
|
||||
}
|
||||
|
||||
console.log('[HLS Loader] getHlsAudioTracks: Raw audioTracks from HLS:', hls.audioTracks)
|
||||
logger.log('[HLS Loader] getHlsAudioTracks: Raw audioTracks from HLS:', hls.audioTracks)
|
||||
|
||||
const audioTracks: AudioTrack[] = hls.audioTracks.map((track: any, index: number) => {
|
||||
const audioTrack = {
|
||||
@@ -111,10 +112,10 @@ export const getHlsAudioTracks = (hls: any): AudioTrack[] => {
|
||||
return audioTrack
|
||||
})
|
||||
|
||||
console.log('[HLS Loader] getHlsAudioTracks: Processed tracks:', audioTracks)
|
||||
logger.log('[HLS Loader] getHlsAudioTracks: Processed tracks:', audioTracks)
|
||||
return audioTracks
|
||||
} catch (error) {
|
||||
console.error('[HLS Loader] getHlsAudioTracks: Error extracting audio tracks:', error)
|
||||
logger.error('[HLS Loader] getHlsAudioTracks: Error extracting audio tracks:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
@@ -154,16 +155,16 @@ export const getHlsSubtitleTracks = (hls: any): SubtitleTrack[] => {
|
||||
export const getHlsQualities = (hls: any): VideoQuality[] => {
|
||||
try {
|
||||
if (!hls) {
|
||||
console.warn('[HLS Loader] getHlsQualities: No HLS instance provided')
|
||||
logger.warn('[HLS Loader] getHlsQualities: No HLS instance provided')
|
||||
return []
|
||||
}
|
||||
|
||||
if (!Array.isArray(hls.levels)) {
|
||||
console.warn('[HLS Loader] getHlsQualities: No levels array found on HLS instance')
|
||||
logger.warn('[HLS Loader] getHlsQualities: No levels array found on HLS instance')
|
||||
return []
|
||||
}
|
||||
|
||||
console.log('[HLS Loader] getHlsQualities: Raw levels from HLS:', hls.levels)
|
||||
logger.log('[HLS Loader] getHlsQualities: Raw levels from HLS:', hls.levels)
|
||||
|
||||
const qualities: VideoQuality[] = hls.levels.map((level: any, index: number) => {
|
||||
const resolution = typeof level.attrs?.RESOLUTION === 'string' ? level.attrs.RESOLUTION : undefined
|
||||
@@ -205,11 +206,12 @@ export const getHlsQualities = (hls: any): VideoQuality[] => {
|
||||
return (b.bitrate || 0) - (a.bitrate || 0)
|
||||
})
|
||||
|
||||
console.log('[HLS Loader] getHlsQualities: Processed qualities:', sortedQualities)
|
||||
logger.log('[HLS Loader] getHlsQualities: Processed qualities:', sortedQualities)
|
||||
return sortedQualities
|
||||
} catch (error) {
|
||||
console.error('[HLS Loader] getHlsQualities: Error extracting qualities:', error)
|
||||
logger.error('[HLS Loader] getHlsQualities: Error extracting qualities:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user