feat: apply phase1 DX cleanup for private registry
This commit is contained in:
+17
-15
@@ -6,6 +6,7 @@
|
||||
|
||||
import { loadFlvjs, isFlvjsSupported, createDefaultFlvConfig } from './rtmpLoader'
|
||||
import { isLiveStream } from './videoProtocol'
|
||||
import { logger } from './logger'
|
||||
|
||||
export interface RtmpSetupOptions {
|
||||
video: HTMLVideoElement
|
||||
@@ -50,7 +51,7 @@ export const setupRtmpInstance = async ({
|
||||
if (src.startsWith('rtmp://') || src.startsWith('rtmps://')) {
|
||||
// For RTMP URLs, flv.js expects HTTP-FLV endpoint
|
||||
// This is a limitation - direct RTMP playback requires server-side conversion
|
||||
console.warn(
|
||||
logger.warn(
|
||||
'Direct RTMP playback requires an HTTP-FLV proxy. Please ensure your RTMP stream is available via HTTP-FLV.'
|
||||
)
|
||||
type = 'flv'
|
||||
@@ -84,40 +85,40 @@ export const setupRtmpInstance = async ({
|
||||
|
||||
// Event handlers
|
||||
player.on(flvjs.Events.ERROR, (errorType: string, errorDetail: string, errorInfo: any) => {
|
||||
console.error('flv.js error:', { errorType, errorDetail, errorInfo })
|
||||
logger.error('flv.js error:', { errorType, errorDetail, errorInfo })
|
||||
|
||||
const error = new Error(`FLV Player Error: ${errorType} - ${errorDetail}`)
|
||||
|
||||
// Handle specific error types
|
||||
if (errorType === flvjs.ErrorTypes.NETWORK_ERROR) {
|
||||
console.error('Network error occurred:', errorDetail)
|
||||
logger.error('Network error occurred:', errorDetail)
|
||||
|
||||
// Attempt recovery for recoverable network errors
|
||||
if (
|
||||
errorDetail === flvjs.ErrorDetails.NETWORK_EXCEPTION ||
|
||||
errorDetail === flvjs.ErrorDetails.NETWORK_STATUS_CODE_INVALID
|
||||
) {
|
||||
console.log('Attempting to recover from network error...')
|
||||
logger.log('Attempting to recover from network error...')
|
||||
try {
|
||||
player.unload()
|
||||
player.load()
|
||||
return
|
||||
} catch (recoveryError) {
|
||||
console.error('Failed to recover from network error:', recoveryError)
|
||||
logger.error('Failed to recover from network error:', recoveryError)
|
||||
}
|
||||
}
|
||||
} else if (errorType === flvjs.ErrorTypes.MEDIA_ERROR) {
|
||||
console.error('Media error occurred:', errorDetail)
|
||||
logger.error('Media error occurred:', errorDetail)
|
||||
|
||||
// Some media errors are recoverable
|
||||
if (errorDetail === flvjs.ErrorDetails.MEDIA_MSE_ERROR) {
|
||||
console.log('Attempting to recover from media error...')
|
||||
logger.log('Attempting to recover from media error...')
|
||||
try {
|
||||
player.unload()
|
||||
player.load()
|
||||
return
|
||||
} catch (recoveryError) {
|
||||
console.error('Failed to recover from media error:', recoveryError)
|
||||
logger.error('Failed to recover from media error:', recoveryError)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,15 +130,15 @@ export const setupRtmpInstance = async ({
|
||||
})
|
||||
|
||||
player.on(flvjs.Events.LOADING_COMPLETE, () => {
|
||||
console.log('flv.js: Loading complete')
|
||||
logger.log('flv.js: Loading complete')
|
||||
})
|
||||
|
||||
player.on(flvjs.Events.RECOVERED_EARLY_EOF, () => {
|
||||
console.log('flv.js: Recovered from early EOF')
|
||||
logger.log('flv.js: Recovered from early EOF')
|
||||
})
|
||||
|
||||
player.on(flvjs.Events.METADATA_ARRIVED, (metadata: any) => {
|
||||
console.log('flv.js: Metadata arrived', metadata)
|
||||
logger.log('flv.js: Metadata arrived', metadata)
|
||||
|
||||
// Trigger onLoadedMetadata callback
|
||||
if (onLoadedMetadata) {
|
||||
@@ -158,7 +159,7 @@ export const setupRtmpInstance = async ({
|
||||
try {
|
||||
await video.play()
|
||||
} catch (playError) {
|
||||
console.warn('Autoplay failed:', playError)
|
||||
logger.warn('Autoplay failed:', playError)
|
||||
// Autoplay might be blocked by browser, ignore error
|
||||
}
|
||||
}
|
||||
@@ -166,7 +167,7 @@ export const setupRtmpInstance = async ({
|
||||
// Return cleanup function
|
||||
return () => {
|
||||
try {
|
||||
console.log('Cleaning up flv.js player...')
|
||||
logger.log('Cleaning up flv.js player...')
|
||||
|
||||
// Remove event listeners
|
||||
player.off(flvjs.Events.ERROR)
|
||||
@@ -189,11 +190,11 @@ export const setupRtmpInstance = async ({
|
||||
delete (video as any).__rtmpInstance
|
||||
delete (video as any).__rtmpStats
|
||||
} catch (cleanupError) {
|
||||
console.error('Error during flv.js cleanup:', cleanupError)
|
||||
logger.error('Error during flv.js cleanup:', cleanupError)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to setup flv.js player:', error)
|
||||
logger.error('Failed to setup flv.js player:', error)
|
||||
|
||||
const setupError =
|
||||
error instanceof Error ? error : new Error('Failed to setup RTMP/FLV player')
|
||||
@@ -238,3 +239,4 @@ export const getRtmpStats = (video: HTMLVideoElement | null): any | null => {
|
||||
export const hasRtmpInstance = (video: HTMLVideoElement | null): boolean => {
|
||||
return getRtmpInstance(video) !== null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user