UNPKG

vidstack

Version:

Build awesome media experiences on the web.

111 lines (108 loc) 2.84 kB
import { peek } from 'maverick.js'; import { isString } from 'maverick.js/std'; import { U as isHLSSupported, p as preconnect } from '../../media-core.js'; import { VideoProvider } from '../video/provider.js'; import { H as HLSController } from './hls.js'; import { H as HLSLibLoader } from './lib-loader.js'; import 'maverick.js/element'; import '../type-check.js'; import '../audio/loader.js'; import 'maverick.js/dom'; import './loader.js'; import '../video/loader.js'; import '../html/provider.js'; import '../html/html–media-events.js'; import '../../media-ui.js'; import '../../icons/icon.js'; import 'media-captions'; import '../html/native-audio-tracks.js'; import '../video/native-hls-text-tracks.js'; import '../video/picture-in-picture.js'; import '../video/presentation/video-presentation.js'; const JS_DELIVR_CDN = "https://cdn.jsdelivr.net"; class HLSProvider extends VideoProvider { $$PROVIDER_TYPE = "HLS"; mh = null; od = new HLSController(this.video); /** * The `hls.js` constructor. */ get ctor() { return this.mh; } /** * The current `hls.js` instance. */ get instance() { return this.od.instance; } /** * Whether `hls.js` is supported in this environment. */ static supported = isHLSSupported(); get type() { return "hls"; } get canLiveSync() { return true; } lh = `${JS_DELIVR_CDN}/npm/hls.js@^1.0.0/dist/hls${".min.js"}`; /** * The `hls.js` configuration object. * * @see {@link https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning} */ get config() { return this.od.nh; } set config(config) { this.od.nh = config; } /** * The `hls.js` constructor (supports dynamic imports) or a URL of where it can be found. * * @defaultValue `https://cdn.jsdelivr.net/npm/hls.js@^1.0.0/dist/hls.min.js` */ get library() { return this.lh; } set library(library) { this.lh = library; } preconnect() { if (!isString(this.lh)) return; preconnect(this.lh); } setup(context) { super.setup(context); new HLSLibLoader(this.lh, context, (ctor) => { this.mh = ctor; this.od.setup(ctor, context); context.delegate.p("provider-setup", { detail: this }); const src = peek(context.$store.source); if (src) this.loadSource(src); }); } async loadSource({ src }) { if (!isString(src)) return; this.od.instance?.loadSource(src); } /** * The given callback is invoked when a new `hls.js` instance is created and right before it's * attached to media. */ onInstance(callback) { const instance = this.od.instance; if (instance) callback(instance); this.od.oh.add(callback); return () => this.od.oh.delete(callback); } destroy() { this.od.Jg(); } } export { HLSProvider };