refactor: strip debug noise to reduce bundle
This commit is contained in:
@@ -131,12 +131,12 @@ export const VideoElement: React.FC<VideoElementProps> = ({
|
||||
|
||||
// Check if it's a CORS-related error
|
||||
const videoError = video.error
|
||||
if (videoError.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED ||
|
||||
videoError.code === MediaError.MEDIA_ERR_NETWORK) {
|
||||
if (
|
||||
videoError.code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED ||
|
||||
videoError.code === MediaError.MEDIA_ERR_NETWORK
|
||||
) {
|
||||
// Could be a CORS issue
|
||||
const corsMessage = getCORSErrorMessage(video.src || src)
|
||||
console.error(corsMessage)
|
||||
errorMessage = `Failed to load video. This might be a CORS issue. Check console for details.`
|
||||
errorMessage = getCORSErrorMessage(video.src || src)
|
||||
}
|
||||
|
||||
const error = new Error(errorMessage)
|
||||
@@ -153,13 +153,11 @@ export const VideoElement: React.FC<VideoElementProps> = ({
|
||||
if (timeSinceLastClick < 300) {
|
||||
// Double click - toggle fullscreen
|
||||
e.preventDefault()
|
||||
console.log('🖱️ [Video Click] Double-click detected, toggling fullscreen')
|
||||
toggleFullscreen()
|
||||
lastClickTimeRef.current = 0
|
||||
} else {
|
||||
// Single click - record time
|
||||
lastClickTimeRef.current = now
|
||||
console.log('🖱️ [Video Click] Single click detected')
|
||||
}
|
||||
},
|
||||
[toggleFullscreen]
|
||||
@@ -208,11 +206,6 @@ export const VideoElement: React.FC<VideoElementProps> = ({
|
||||
return
|
||||
}
|
||||
|
||||
// Log warning if external URL
|
||||
if (validation.warning) {
|
||||
console.warn(`⚠️ [Video] ${validation.warning}`)
|
||||
}
|
||||
|
||||
const isHLS = src.includes('.m3u8')
|
||||
let cleanupFn: (() => void) | null = null
|
||||
|
||||
@@ -237,54 +230,41 @@ export const VideoElement: React.FC<VideoElementProps> = ({
|
||||
hls.attachMedia(video)
|
||||
|
||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||
console.log('✅ [HLS] Manifest parsed successfully')
|
||||
|
||||
// Extract audio tracks after manifest is parsed
|
||||
// Sometimes audio tracks are not immediately available, so we try with a small delay
|
||||
setTimeout(() => {
|
||||
const tracks = getHlsAudioTracks(hls)
|
||||
|
||||
if (tracks.length > 0) {
|
||||
console.log(`✅ [HLS] Found ${tracks.length} audio tracks:`, tracks)
|
||||
setAvailableAudioTracks(tracks)
|
||||
onAudioTracksLoaded?.(tracks)
|
||||
} else {
|
||||
console.log('ℹ️ [HLS] No audio tracks found in manifest')
|
||||
}
|
||||
}, 100)
|
||||
|
||||
if (autoplay) {
|
||||
video.play().catch((err) => {
|
||||
console.warn('⚠️ [HLS] Autoplay prevented:', err)
|
||||
})
|
||||
void video.play().catch(() => undefined)
|
||||
}
|
||||
})
|
||||
|
||||
// Also listen to audio track updates
|
||||
hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, (_event: any, data: any) => {
|
||||
console.log('🔄 [HLS] Audio tracks updated:', data)
|
||||
hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, () => {
|
||||
const tracks = getHlsAudioTracks(hls)
|
||||
if (tracks.length > 0) {
|
||||
console.log(`✅ [HLS] Found ${tracks.length} audio tracks after update:`, tracks)
|
||||
setAvailableAudioTracks(tracks)
|
||||
onAudioTracksLoaded?.(tracks)
|
||||
}
|
||||
})
|
||||
|
||||
hls.on(Hls.Events.ERROR, (_event: any, data: any) => {
|
||||
console.error('❌ [HLS] Error:', data)
|
||||
if (data.fatal) {
|
||||
switch (data.type) {
|
||||
case Hls.ErrorTypes.NETWORK_ERROR:
|
||||
console.error('❌ [HLS] Fatal network error, trying to recover...')
|
||||
hls.startLoad()
|
||||
break
|
||||
case Hls.ErrorTypes.MEDIA_ERROR:
|
||||
console.error('❌ [HLS] Fatal media error, trying to recover...')
|
||||
hls.recoverMediaError()
|
||||
break
|
||||
default:
|
||||
console.error('❌ [HLS] Fatal error, cannot recover')
|
||||
handleError()
|
||||
break
|
||||
}
|
||||
@@ -296,19 +276,16 @@ export const VideoElement: React.FC<VideoElementProps> = ({
|
||||
|
||||
// Setup cleanup function
|
||||
cleanupFn = () => {
|
||||
console.log('🧹 [HLS] Cleaning up HLS instance...')
|
||||
if (hls) {
|
||||
hls.destroy()
|
||||
}
|
||||
delete (video as any).__hlsInstance
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('❌ [HLS] Failed to load or initialize hls.js:', err)
|
||||
let error: Error
|
||||
if (err instanceof Error && isCORSError(err)) {
|
||||
const corsMessage = getCORSErrorMessage(src)
|
||||
console.error(corsMessage)
|
||||
error = new Error('Failed to load HLS stream. This might be a CORS issue. Check console for details.')
|
||||
error = new Error(corsMessage)
|
||||
} else {
|
||||
error = err instanceof Error ? err : new Error('Failed to load HLS')
|
||||
}
|
||||
@@ -323,9 +300,7 @@ export const VideoElement: React.FC<VideoElementProps> = ({
|
||||
// Native support or regular video
|
||||
video.src = src
|
||||
if (autoplay) {
|
||||
video.play().catch((err) => {
|
||||
console.warn('⚠️ [Video] Autoplay prevented:', err)
|
||||
})
|
||||
void video.play().catch(() => undefined)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -363,7 +338,6 @@ export const VideoElement: React.FC<VideoElementProps> = ({
|
||||
|
||||
if (trackIndex !== -1) {
|
||||
setHlsAudioTrack(hlsInstance, trackIndex)
|
||||
console.log(`✅ [Video] Audio track changed to: ${settings.audioTrack.name}`)
|
||||
}
|
||||
}, [settings.audioTrack, availableAudioTracks, videoRef])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user