From 3d3a84997253cb1af1ae9ee0ad25972256a7dafb Mon Sep 17 00:00:00 2001 From: CY Date: Thu, 25 Aug 2022 05:58:49 +0000 Subject: [PATCH] . --- packages/hls/src/index.ts | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/hls/src/index.ts b/packages/hls/src/index.ts index 96f7b694..6e4f8d8b 100644 --- a/packages/hls/src/index.ts +++ b/packages/hls/src/index.ts @@ -21,7 +21,7 @@ const hlsPlugin = ({ matcher = defaultMatcher }: hlsPluginOptions = {}): PlayerPlugin => { let isInitial = false - let hlsInstance: Hls | null = null + let hlsInstance: Hls const getHls = (options?: Partial): Hls => { if (hlsInstance) { @@ -33,12 +33,12 @@ const hlsPlugin = ({ return { name: PLUGIN_NAME, - load: ({ on, emit, offAny }, video, source) => { + load: ({ on, emit }, video, source) => { if (!matcher(video, source)) return false hlsInstance = getHls({ autoStartLoad: false, ...hlsConfig }) - if (!hlsInstance || !Hls.isSupported()) { + if (!Hls.isSupported()) { emit('pluginerror', { payload: { type: 'hlsNotSupported', @@ -51,19 +51,24 @@ const hlsPlugin = ({ if (!isInitial) { emit('loadedplugin', { name: PLUGIN_NAME }) isInitial = true - offAny('canplay') //onReady is handled by hls.js } - hlsInstance?.attachMedia(video) - hlsInstance?.loadSource(source.src) - hlsInstance?.startLoad() + hlsInstance.attachMedia(video) + hlsInstance.loadSource(source.src) + hlsInstance.startLoad() + + //TODO: remove video onReady Listener + // onReady is handled by hls.js + // hlsInstance.on( + // Hls.Events.MANIFEST_PARSED, + // (event: Events.MANIFEST_PARSED, data: ManifestParsedData) => { + // emit('canplay', { type: event, payload: data }) + // } + // ) Object.values(Hls.Events).forEach((e) => { - hlsInstance?.on(e as any, (event: string, data: ErrorData) => { - if ( - event === Hls.Events.ERROR && - data.details == 'manifestLoadError' /*ErrorDetails.MANIFEST_LOAD_ERROR*/ - ) { + hlsInstance.on(e as any, (event: string, data: ErrorData) => { + if (event === Hls.Events.ERROR && data.details == Hls.ErrorDetails.MANIFEST_LOAD_ERROR) { emit('pluginerror', { message: data.type, ...data }) } emit(event, data) @@ -71,11 +76,14 @@ const hlsPlugin = ({ }) on('destroy', () => { - hlsInstance?.destroy() - hlsInstance = null + hlsInstance.destroy() + hlsInstance = null as any }) return true + }, + apply: () => { + // restore video onready listener } } }