//@ts-check import JadefinIntegrity from '../../JadefinIntegrity.js'; import Jadefin from "../../Jadefin.js"; import JadefinMod from "../../JadefinMod.js"; import JadefinModules from "../../JadefinModules.js"; // Mainly spawned from https://github.com/jellyfin/jellyfin-android/issues/1031 export default JadefinIntegrity("PatchAndroidHLSJS", import.meta.url, () => new (class PatchAndroidHLSJS extends JadefinMod { constructor() { super(); this.enableHlsJsPlayer = this.enableHlsJsPlayer.bind(this); } get isEnabled() { return this.storage.get("isEnabled", false); } set isEnabled(value) { this.storage.set("isEnabled", value); } async init(name, url) { await super.init(name, url); const htmlMediaHelper = this.htmlMediaPlayer = Jadefin.findWebpackRawLoad(e => (e.JQ?.toString().indexOf("x-mpegURL") || -1) != -1)[0]; this._enableHlsJsPlayer = htmlMediaHelper.JQ.bind(htmlMediaHelper); Object.defineProperty(htmlMediaHelper, "JQ", { get: () => this.enableHlsJsPlayer }); const ExtrasMenu = /** @type {import("../ExtrasMenu.js").default} */ (Jadefin.getMod("ExtrasMenu")); ExtrasMenu.items.push({ name: "Enable HLS.js", secondaryText: "Sometimes helps with playback in some browsers", icon: "auto_fix_normal", in: ExtrasMenu.IN_CUSTOM, inCustom: (current, item) => { if (!this.isEnabled) { item.name = "Enable HLS.js"; item.icon = "auto_fix_normal"; } else { item.name = "Disable HLS.js"; item.icon = "auto_fix_off"; } return true; }, cb: () => { this.isEnabled = !this.isEnabled; } }); } enableHlsJsPlayer(runTimeTicks, mediaType) { if (this.isEnabled) { return true; } // https://github.com/jellyfin/jellyfin-web/commit/baf1b55a0cb83d4cb63a18968fc93493ce785498 if (JadefinModules.browser.android && mediaType === "Video") { mediaType = "Audio"; } return this._enableHlsJsPlayer?.(runTimeTicks, mediaType); } })());