diff --git a/cmd/mjpeg-player/hlsjs/loader/playlist-loader.js b/cmd/mjpeg-player/hlsjs/loader/playlist-loader.js index e34f236b..bf2422f9 100644 --- a/cmd/mjpeg-player/hlsjs/loader/playlist-loader.js +++ b/cmd/mjpeg-player/hlsjs/loader/playlist-loader.js @@ -48,6 +48,67 @@ class PlaylistLoader extends EventHandler { type !== PlaylistContextType.SUBTITLE_TRACK); } + /** + * Map context.type to LevelType + * @param {PlaylistLoaderContext} context + * @returns {LevelType} + */ + static mapContextToLevelType(context) { + const { type } = context; + + switch (type) { + case PlaylistContextType.AUDIO_TRACK: + return PlaylistLevelType.AUDIO; + case PlaylistContextType.SUBTITLE_TRACK: + return PlaylistLevelType.SUBTITLE; + default: + return PlaylistLevelType.MAIN; + } + } + + static getResponseUrl(response, context) { + let url = response.url; + // responseURL not supported on some browsers (it is used to detect URL redirection) + // data-uri mode also not supported (but no need to detect redirection) + if (url === undefined || url.indexOf('data:') === 0) { + // fallback to initial URL + url = context.url; + } + return url; + } + + /** + * Returns defaults or configured loader-type overloads (pLoader and loader config params) + * Default loader is XHRLoader (see utils) + * @param {PlaylistLoaderContext} context + * @returns {Loader} or other compatible configured overload + */ + createInternalLoader(context) { + const config = this.hls.config; + const PLoader = config.pLoader; + const Loader = config.loader; + // TODO(typescript-config): Verify once config is typed that InternalLoader always returns a Loader + const InternalLoader = PLoader || Loader; + + const loader = new InternalLoader(config); + + // TODO - Do we really need to assign the instance or if the dep has been lost + context.loader = loader; + this.loaders[context.type] = loader; + + return loader; + } + + getInternalLoader(context) { + return this.loaders[context.type]; + } + + resetInternalLoader(contextType) { + if (this.loaders[contextType]) { + delete this.loaders[contextType]; + } + } + onManifestLoading(data) { this.load({ url: data.url, @@ -89,67 +150,6 @@ class PlaylistLoader extends EventHandler { }); } - static getResponseUrl(response, context) { - let url = response.url; - // responseURL not supported on some browsers (it is used to detect URL redirection) - // data-uri mode also not supported (but no need to detect redirection) - if (url === undefined || url.indexOf('data:') === 0) { - // fallback to initial URL - url = context.url; - } - return url; - } - - /** - * Map context.type to LevelType - * @param {PlaylistLoaderContext} context - * @returns {LevelType} - */ - static mapContextToLevelType(context) { - const { type } = context; - - switch (type) { - case PlaylistContextType.AUDIO_TRACK: - return PlaylistLevelType.AUDIO; - case PlaylistContextType.SUBTITLE_TRACK: - return PlaylistLevelType.SUBTITLE; - default: - return PlaylistLevelType.MAIN; - } - } - - getInternalLoader(context) { - return this.loaders[context.type]; - } - - /** - * Returns defaults or configured loader-type overloads (pLoader and loader config params) - * Default loader is XHRLoader (see utils) - * @param {PlaylistLoaderContext} context - * @returns {Loader} or other compatible configured overload - */ - createInternalLoader(context) { - const config = this.hls.config; - const PLoader = config.pLoader; - const Loader = config.loader; - // TODO(typescript-config): Verify once config is typed that InternalLoader always returns a Loader - const InternalLoader = PLoader || Loader; - - const loader = new InternalLoader(config); - - // TODO - Do we really need to assign the instance or if the dep has been lost - context.loader = loader; - this.loaders[context.type] = loader; - - return loader; - } - - resetInternalLoader(contextType) { - if (this.loaders[contextType]) { - delete this.loaders[contextType]; - } - } - load(context) { const config = this.hls.config;