release: v3.0.0
This commit is contained in:
+15
-17
@@ -10,16 +10,16 @@ import { logger } from './logger'
|
||||
// Re-export control functions for backward compatibility
|
||||
export { setHlsQualityLevel, setHlsAudioTrack } from './hlsControl'
|
||||
|
||||
const HLS_CDN_URL = 'https://cdn.jsdelivr.net/npm/hls.js@1.5.13/dist/hls.min.js'
|
||||
const HLS_CDN_URL = 'https://cdn.jsdelivr.net/npm/hls.js@1.6.13/dist/hls.min.js'
|
||||
|
||||
/**
|
||||
* Load hls.js from CDN as fallback
|
||||
*/
|
||||
const loadHlsFromCDN = (): Promise<any> => {
|
||||
const loadHlsFromCDN = (): Promise<HlsConstructor> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Check if already loaded globally
|
||||
if (typeof (window as any).Hls !== 'undefined') {
|
||||
resolve((window as any).Hls)
|
||||
if (window.Hls) {
|
||||
resolve(window.Hls)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ const loadHlsFromCDN = (): Promise<any> => {
|
||||
script.async = true
|
||||
|
||||
script.onload = () => {
|
||||
if (typeof (window as any).Hls !== 'undefined') {
|
||||
resolve((window as any).Hls)
|
||||
if (window.Hls) {
|
||||
resolve(window.Hls)
|
||||
} else {
|
||||
reject(new Error('HLS.js CDN loaded but Hls global not found'))
|
||||
}
|
||||
@@ -46,7 +46,7 @@ const loadHlsFromCDN = (): Promise<any> => {
|
||||
/**
|
||||
* Load hls.js with npm fallback to CDN
|
||||
*/
|
||||
export const loadHls = async (): Promise<any> => {
|
||||
export const loadHls = async (): Promise<HlsConstructor> => {
|
||||
try {
|
||||
logger.log('[HLS Loader] Attempting to load from npm package...')
|
||||
// Try loading from npm package first
|
||||
@@ -70,7 +70,7 @@ export const loadHls = async (): Promise<any> => {
|
||||
/**
|
||||
* Check if HLS.js is supported in current browser
|
||||
*/
|
||||
export const isHlsSupported = (Hls: any): boolean => {
|
||||
export const isHlsSupported = (Hls: HlsConstructor): boolean => {
|
||||
return Hls && typeof Hls.isSupported === 'function' && Hls.isSupported()
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ export const hasNativeHlsSupport = (): boolean => {
|
||||
/**
|
||||
* Extract audio tracks from HLS instance
|
||||
*/
|
||||
export const getHlsAudioTracks = (hls: any): AudioTrack[] => {
|
||||
export const getHlsAudioTracks = (hls: HlsInstance): AudioTrack[] => {
|
||||
try {
|
||||
if (!hls) {
|
||||
logger.warn('[HLS Loader] getHlsAudioTracks: No HLS instance provided')
|
||||
@@ -100,7 +100,7 @@ export const getHlsAudioTracks = (hls: any): AudioTrack[] => {
|
||||
|
||||
logger.log('[HLS Loader] getHlsAudioTracks: Raw audioTracks from HLS:', hls.audioTracks)
|
||||
|
||||
const audioTracks: AudioTrack[] = hls.audioTracks.map((track: any, index: number) => {
|
||||
const audioTracks: AudioTrack[] = hls.audioTracks.map((track: HlsAudioTrack, index: number) => {
|
||||
const audioTrack = {
|
||||
name: track.name || track.label || `Audio ${index + 1}`,
|
||||
language: track.lang || track.language || 'unknown',
|
||||
@@ -123,7 +123,7 @@ export const getHlsAudioTracks = (hls: any): AudioTrack[] => {
|
||||
/**
|
||||
* Extract subtitle tracks from HLS instance
|
||||
*/
|
||||
export const getHlsSubtitleTracks = (hls: any): SubtitleTrack[] => {
|
||||
export const getHlsSubtitleTracks = (hls: HlsInstance): SubtitleTrack[] => {
|
||||
try {
|
||||
if (!hls) {
|
||||
return []
|
||||
@@ -134,7 +134,7 @@ export const getHlsSubtitleTracks = (hls: any): SubtitleTrack[] => {
|
||||
return []
|
||||
}
|
||||
|
||||
const subtitleTracks: SubtitleTrack[] = hls.subtitleTracks.map((track: any, index: number) => {
|
||||
const subtitleTracks: SubtitleTrack[] = hls.subtitleTracks.map((track: HlsSubtitleTrack, index: number) => {
|
||||
return {
|
||||
label: track.name || track.label || `Subtitle ${index + 1}`,
|
||||
lang: track.lang || track.language || 'unknown',
|
||||
@@ -152,7 +152,7 @@ export const getHlsSubtitleTracks = (hls: any): SubtitleTrack[] => {
|
||||
/**
|
||||
* Extract available quality levels from HLS instance
|
||||
*/
|
||||
export const getHlsQualities = (hls: any): VideoQuality[] => {
|
||||
export const getHlsQualities = (hls: HlsInstance): VideoQuality[] => {
|
||||
try {
|
||||
if (!hls) {
|
||||
logger.warn('[HLS Loader] getHlsQualities: No HLS instance provided')
|
||||
@@ -166,7 +166,7 @@ export const getHlsQualities = (hls: any): VideoQuality[] => {
|
||||
|
||||
logger.log('[HLS Loader] getHlsQualities: Raw levels from HLS:', hls.levels)
|
||||
|
||||
const qualities: VideoQuality[] = hls.levels.map((level: any, index: number) => {
|
||||
const qualities: VideoQuality[] = hls.levels.map((level: HlsLevel, index: number) => {
|
||||
const resolution = typeof level.attrs?.RESOLUTION === 'string' ? level.attrs.RESOLUTION : undefined
|
||||
const [widthFromResolution, heightFromResolution] = resolution
|
||||
? resolution.split('x').map((value: string) => parseInt(value, 10))
|
||||
@@ -175,7 +175,7 @@ export const getHlsQualities = (hls: any): VideoQuality[] => {
|
||||
const translations = getTranslations(detectBrowserLanguage());
|
||||
const width = level.width || widthFromResolution
|
||||
const height = level.height || heightFromResolution
|
||||
const bitrate = typeof level.bitrate === 'number' ? level.bitrate : level.attrs?.BANDWIDTH
|
||||
const bitrate = typeof level.bitrate === 'number' ? level.bitrate : (level.attrs?.BANDWIDTH ? parseInt(level.attrs.BANDWIDTH, 10) : undefined)
|
||||
|
||||
let label: string
|
||||
if (typeof level.name === 'string' && level.name.trim().length > 0) {
|
||||
@@ -213,5 +213,3 @@ export const getHlsQualities = (hls: any): VideoQuality[] => {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user