import { b as e, e as t } from "./chunk.BlbRoQQ3.js";
import { b as n, c as r } from "./patterns.CVV2epWU.js";
import "./cjs.S1Glohke.js";
var i = /* @__PURE__ */ e(((exports, i) => {
	var a = Object.create, o = Object.defineProperty, s = Object.getOwnPropertyDescriptor, c = Object.getOwnPropertyNames, l = Object.getPrototypeOf, u = Object.prototype.hasOwnProperty, d = (e, t, n) => t in e ? o(e, t, {
		enumerable: !0,
		configurable: !0,
		writable: !0,
		value: n
	}) : e[t] = n, f = (e, t) => {
		for (var n in t) o(e, n, {
			get: t[n],
			enumerable: !0
		});
	}, p = (e, t, n, r) => {
		if (t && typeof t == "object" || typeof t == "function") for (let i of c(t)) !u.call(e, i) && i !== n && o(e, i, {
			get: () => t[i],
			enumerable: !(r = s(t, i)) || r.enumerable
		});
		return e;
	}, m = (e, t, n) => (n = e == null ? {} : a(l(e)), p(t || !e || !e.__esModule ? o(n, "default", {
		value: e,
		enumerable: !0
	}) : n, e)), h = (e) => p(o({}, "__esModule", { value: !0 }), e), g = (e, t, n) => (d(e, typeof t == "symbol" ? t : t + "", n), n), _ = {};
	f(_, { default: () => D }), i.exports = h(_);
	var v = m(t("react")), y = r(), b = n();
	let x = typeof navigator < "u", S = x && navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1, C = x && (/iPad|iPhone|iPod/.test(navigator.userAgent) || S) && !window.MSStream, w = x && /^((?!chrome|android).)*safari/i.test(navigator.userAgent) && !window.MSStream, T = /www\.dropbox\.com\/.+/, E = /https:\/\/watch\.cloudflarestream\.com\/([a-z0-9]+)/;
	var D = class extends v.Component {
		constructor() {
			super(...arguments), g(this, "onReady", (...e) => this.props.onReady(...e)), g(this, "onPlay", (...e) => this.props.onPlay(...e)), g(this, "onBuffer", (...e) => this.props.onBuffer(...e)), g(this, "onBufferEnd", (...e) => this.props.onBufferEnd(...e)), g(this, "onPause", (...e) => this.props.onPause(...e)), g(this, "onEnded", (...e) => this.props.onEnded(...e)), g(this, "onError", (...e) => this.props.onError(...e)), g(this, "onPlayBackRateChange", (e) => this.props.onPlaybackRateChange(e.target.playbackRate)), g(this, "onEnablePIP", (...e) => this.props.onEnablePIP(...e)), g(this, "onDisablePIP", (e) => {
				let { onDisablePIP: t, playing: n } = this.props;
				t(e), n && this.play();
			}), g(this, "onPresentationModeChange", (e) => {
				if (this.player && (0, y.supportsWebKitPresentationMode)(this.player)) {
					let { webkitPresentationMode: t } = this.player;
					t === "picture-in-picture" ? this.onEnablePIP(e) : t === "inline" && this.onDisablePIP(e);
				}
			}), g(this, "onSeek", (e) => {
				this.props.onSeek(e.target.currentTime);
			}), g(this, "mute", () => {
				this.player.muted = !0;
			}), g(this, "unmute", () => {
				this.player.muted = !1;
			}), g(this, "renderSourceElement", (e, t) => typeof e == "string" ? /* @__PURE__ */ v.default.createElement("source", {
				key: t,
				src: e
			}) : /* @__PURE__ */ v.default.createElement("source", {
				key: t,
				...e
			})), g(this, "renderTrack", (e, t) => /* @__PURE__ */ v.default.createElement("track", {
				key: t,
				...e
			})), g(this, "ref", (e) => {
				this.player && (this.prevPlayer = this.player), this.player = e;
			});
		}
		componentDidMount() {
			this.props.onMount && this.props.onMount(this), this.addListeners(this.player);
			let e = this.getSource(this.props.url);
			e && (this.player.src = e), (C || this.props.config.forceDisableHls) && this.player.load();
		}
		componentDidUpdate(e) {
			this.shouldUseAudio(this.props) !== this.shouldUseAudio(e) && (this.removeListeners(this.prevPlayer, e.url), this.addListeners(this.player)), this.props.url !== e.url && !(0, y.isMediaStream)(this.props.url) && !(this.props.url instanceof Array) && (this.player.srcObject = null);
		}
		componentWillUnmount() {
			this.player.removeAttribute("src"), this.removeListeners(this.player), this.hls && this.hls.destroy();
		}
		addListeners(e) {
			let { url: t, playsinline: n } = this.props;
			e.addEventListener("play", this.onPlay), e.addEventListener("waiting", this.onBuffer), e.addEventListener("playing", this.onBufferEnd), e.addEventListener("pause", this.onPause), e.addEventListener("seeked", this.onSeek), e.addEventListener("ended", this.onEnded), e.addEventListener("error", this.onError), e.addEventListener("ratechange", this.onPlayBackRateChange), e.addEventListener("enterpictureinpicture", this.onEnablePIP), e.addEventListener("leavepictureinpicture", this.onDisablePIP), e.addEventListener("webkitpresentationmodechanged", this.onPresentationModeChange), this.shouldUseHLS(t) || e.addEventListener("canplay", this.onReady), n && (e.setAttribute("playsinline", ""), e.setAttribute("webkit-playsinline", ""), e.setAttribute("x5-playsinline", ""));
		}
		removeListeners(e, t) {
			e.removeEventListener("canplay", this.onReady), e.removeEventListener("play", this.onPlay), e.removeEventListener("waiting", this.onBuffer), e.removeEventListener("playing", this.onBufferEnd), e.removeEventListener("pause", this.onPause), e.removeEventListener("seeked", this.onSeek), e.removeEventListener("ended", this.onEnded), e.removeEventListener("error", this.onError), e.removeEventListener("ratechange", this.onPlayBackRateChange), e.removeEventListener("enterpictureinpicture", this.onEnablePIP), e.removeEventListener("leavepictureinpicture", this.onDisablePIP), e.removeEventListener("webkitpresentationmodechanged", this.onPresentationModeChange), this.shouldUseHLS(t) || e.removeEventListener("canplay", this.onReady);
		}
		shouldUseAudio(e) {
			return e.config.forceVideo || e.config.attributes.poster ? !1 : b.AUDIO_EXTENSIONS.test(e.url) || e.config.forceAudio;
		}
		shouldUseHLS(e) {
			return w && this.props.config.forceSafariHLS || this.props.config.forceHLS ? !0 : C || this.props.config.forceDisableHls ? !1 : b.HLS_EXTENSIONS.test(e) || E.test(e);
		}
		shouldUseDASH(e) {
			return b.DASH_EXTENSIONS.test(e) || this.props.config.forceDASH;
		}
		shouldUseFLV(e) {
			return b.FLV_EXTENSIONS.test(e) || this.props.config.forceFLV;
		}
		load(e) {
			let { hlsVersion: t, hlsOptions: n, dashVersion: r, flvVersion: i } = this.props.config;
			if (this.hls && this.hls.destroy(), this.dash && this.dash.reset(), this.shouldUseHLS(e) && (0, y.getSDK)("https://cdn.jsdelivr.net/npm/hls.js@VERSION/dist/hls.min.js".replace("VERSION", t), "Hls").then((t) => {
				if (this.hls = new t(n), this.hls.on(t.Events.MANIFEST_PARSED, () => {
					this.props.onReady();
				}), this.hls.on(t.Events.ERROR, (e, n) => {
					this.props.onError(e, n, this.hls, t);
				}), E.test(e)) {
					let t = e.match(E)[1];
					this.hls.loadSource("https://videodelivery.net/{id}/manifest/video.m3u8".replace("{id}", t));
				} else this.hls.loadSource(e);
				this.hls.attachMedia(this.player), this.props.onLoaded();
			}), this.shouldUseDASH(e) && (0, y.getSDK)("https://cdnjs.cloudflare.com/ajax/libs/dashjs/VERSION/dash.all.min.js".replace("VERSION", r), "dashjs").then((t) => {
				this.dash = t.MediaPlayer().create(), this.dash.initialize(this.player, e, this.props.playing), this.dash.on("error", this.props.onError), parseInt(r) < 3 ? this.dash.getDebug().setLogToBrowserConsole(!1) : this.dash.updateSettings({ debug: { logLevel: t.Debug.LOG_LEVEL_NONE } }), this.props.onLoaded();
			}), this.shouldUseFLV(e) && (0, y.getSDK)("https://cdn.jsdelivr.net/npm/flv.js@VERSION/dist/flv.min.js".replace("VERSION", i), "flvjs").then((t) => {
				this.flv = t.createPlayer({
					type: "flv",
					url: e
				}), this.flv.attachMediaElement(this.player), this.flv.on(t.Events.ERROR, (e, n) => {
					this.props.onError(e, n, this.flv, t);
				}), this.flv.load(), this.props.onLoaded();
			}), e instanceof Array) this.player.load();
			else if ((0, y.isMediaStream)(e)) try {
				this.player.srcObject = e;
			} catch {
				this.player.src = window.URL.createObjectURL(e);
			}
		}
		play() {
			let e = this.player.play();
			e && e.catch(this.props.onError);
		}
		pause() {
			this.player.pause();
		}
		stop() {
			this.player.removeAttribute("src"), this.dash && this.dash.reset();
		}
		seekTo(e, t = !0) {
			this.player.currentTime = e, t || this.pause();
		}
		setVolume(e) {
			this.player.volume = e;
		}
		enablePIP() {
			this.player.requestPictureInPicture && document.pictureInPictureElement !== this.player ? this.player.requestPictureInPicture() : (0, y.supportsWebKitPresentationMode)(this.player) && this.player.webkitPresentationMode !== "picture-in-picture" && this.player.webkitSetPresentationMode("picture-in-picture");
		}
		disablePIP() {
			document.exitPictureInPicture && document.pictureInPictureElement === this.player ? document.exitPictureInPicture() : (0, y.supportsWebKitPresentationMode)(this.player) && this.player.webkitPresentationMode !== "inline" && this.player.webkitSetPresentationMode("inline");
		}
		setPlaybackRate(e) {
			try {
				this.player.playbackRate = e;
			} catch (e) {
				this.props.onError(e);
			}
		}
		getDuration() {
			if (!this.player) return null;
			let { duration: e, seekable: t } = this.player;
			return e === Infinity && t.length > 0 ? t.end(t.length - 1) : e;
		}
		getCurrentTime() {
			return this.player ? this.player.currentTime : null;
		}
		getSecondsLoaded() {
			if (!this.player) return null;
			let { buffered: e } = this.player;
			if (e.length === 0) return 0;
			let t = e.end(e.length - 1), n = this.getDuration();
			return t > n ? n : t;
		}
		getSource(e) {
			let t = this.shouldUseHLS(e), n = this.shouldUseDASH(e), r = this.shouldUseFLV(e);
			if (!(e instanceof Array || (0, y.isMediaStream)(e) || t || n || r)) return T.test(e) ? e.replace("www.dropbox.com", "dl.dropboxusercontent.com") : e;
		}
		render() {
			let { url: e, playing: t, loop: n, controls: r, muted: i, config: a, width: o, height: s } = this.props, c = this.shouldUseAudio(this.props), l = c ? "audio" : "video", u = {
				width: o === "auto" ? o : "100%",
				height: s === "auto" ? s : "100%"
			};
			return /* @__PURE__ */ v.default.createElement(l, {
				ref: this.ref,
				src: this.getSource(e),
				style: u,
				preload: "auto",
				autoPlay: t || void 0,
				controls: r,
				muted: i,
				loop: n,
				...a.attributes
			}, e instanceof Array && e.map(this.renderSourceElement), a.tracks.map(this.renderTrack));
		}
	};
	g(D, "displayName", "FilePlayer"), g(D, "canPlay", b.canPlay.file);
}));
export default i();

//# sourceMappingURL=FilePlayer.BRcfPyeT.js.map